I’ve a question about Entity Framework. In a code first scenario I have a person class that references an address. In my domain I would have this as a reference to the Address class. All the examples of Entity Framework I’ve seen also require an AddressId field. This is something that I think shouldn’t be there and isn’t required in my domain driven model.
Why does EF require this? Can I do without it (I don’t believe NHibernate requires this).
Thanks
public class Person()
{
public int Id {get;set;}
public string Name {get;set;}
public Address Address {get;set;}
public int AddressId {get;set;} //Entity Framework seems to require this
}
You should read up on Independent Association and Foreign Key Association:
Code First: Independent associations vs. Foreign key associations?
A good article from the same author who answered the question above is also avialable at:
foreign-key-vs-independent-associations-in-ef-4