I'm using the Entity Framework as my ORM for an ASP.Net (webforms) application. Suppose I had a "list/detail" set of pages in my application, when you click on a row in the list page I would want to pass an ID of some type for that row to a detail page, which I'd then use to load the row from my data layer. In my specific case, the primary key is simply a "rowId" identity column.
EF, however, seems to prefer to "hide" the primary/foreign keys so that you don't get access to them (by default).
I'm new to EF, and I'm wondering if there is a best-practice for uniquely identifying a row outside of the context of the entity. I imagine I could add a uniqueidentifier column to my record and a matching property to my entity model, but it seems redundant to effectively have 2 unique identifiers for the row. Is there a better way to carry around an identifier out at the presentation layer?
In my _ItemDataBound() event handler, I'm thinking I can do something like:
var announcement = (Announcement) e.Item.DataItem;
string rowID = announcement.EntityKey.EntityKeyValues[0].Value.ToString();
Is this recommended, or just working against the framework?
Thanks in advance.
Scott