Entity Framework Code First initializing foreign keys

c# ef-code-first entity-framework entity-framework-6

Accepted Answer

ZZZ_tmp
2
2/27/2016 4:36:19 PM

Popular Answer

A foreign key between Family and Member does not have to be specifically defined. If you need it, Entity Framework will handle this for you. Given that you've already mentioned this quality

public virtual ICollection<Member> FamilyMembers { get; set; }

The foreign key is generated on the Family class during the initial Add-Migration or Update-database operation. Therefore, you don't require the property.

public virtual FamilyFK { get; set; }


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow