c# - How would I uniquely identify an entity in Entity Framework? -
I am using entity framework as my ORM for an asp.net (webforms) application. Suppose I had a "list / extension" set of pages in my application, when you click on a row in the list page, I would like to pass some type of ID of that line to the details page, which I In my specific case to load the row from my data level, the primary key is only a "line ID" identity column.
However, EF likes to hide the primary / foreign key, so you can not access them (by default).
I am new to EF, and I am thinking that there is a best practice to identify a line outside the context of the unit. I think I can add a unique identifier column and a matching property to my unit model for my record, but it seems to be meaningless for 2 unique identifiers for this line, to carry out the identifier at the presentation level Is a Better Way?
In my _ItemDataBound () event handler, I am thinking that I can do something like this:
Var declaration = (announcement) e.Item.DataItem; String line id = declaration. Antitiki Antitigroup [0]. Value Toasting ();
Is it recommended, or is it just working against the structure?
Thanks in advance.
Scott
No, what you are doing is "(unit) framework Does not work against. " It is not to say that this correction can not be done, however:
- I know that it is not MVC, but even in webforms, I think it is your data There is a good idea to be somewhat different between Layers and your web page, I probably will use repository patterns with a presentation model, but instead of giving the page the direct knowledge of the unit framework.
- Because you have already announced your appropriate type, you can access the ID value directly, instead of going through EntityKey, at least, at the end of your page the Entity Framework Instead of the knowledge of the declaration.
- The current code assumes that there is an entity (not always true, especially with newly entered entities committed to the database which have not yet happened) and they have only one column.
Comments
Post a Comment