Reputation: 55
I am new to ASP.NET MVC and spend some time on creating forms for entities with related entities.
While looking for the best way to achieve this, I figured out that most examples on the Internet use an ugly way of referencing related objects.
For example, see this excerpt of the MVC Music Store tutorial:
http://s8.postimage.org/mmevixep1/orm_mvc.png http://s8.postimage.org/mmevixep1/orm_mvc.png
I found the same approach in other tutorials too, for example this one ("Modifying the Course Entity", there is a DepartmentID and an Department object).
I was confused about the fact that the whole idea behind ORM is dropped here. But I also found out that it's not (or hardly) possible to update a related entity without 'foreign key properties'.
Can someone explain why Microsoft uses this approach, and whether there are alternatives?
Upvotes: 0
Views: 116
Reputation: 76
Foreign key fields don't have to be included in the model. Actually, this functionality was only included in .Net 4.0. This link has a god explanation about relationships in .Net Entity Framework.
Upvotes: 1