EF-Code first complex type with a navigational property

旧街凉风 提交于 2019-12-01 02:53:59

Navigation properties (refering to other entities) on a complex type are not supported. You must either make your Location an entity (with its own table) or remove the navigation property Country from Location (and add the [ComplexType] attribute as mentioned by Steve Morgan).

Edit

Reference: http://msdn.microsoft.com/en-us/library/bb738472.aspx

"Complex type cannot contain navigation properties."

EF wants to infer a primary key for Location, but can't.

Add a public int LocationId { get; set; } to the Location class and it should be happy.

If you want to use Location as a complex type, annotate it with a [ComplexType] attribute.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!