How do I add a navigation property for a Entity Framework Complex Type

房东的猫 提交于 2019-12-12 08:54:24

问题


I'm using VS2010 Beta 2, I have a Complex Type called Address with the following properties:

  • Street
  • City
  • CountryId

I have a Country Entity defined in my Model, but I can't seem to find a way to add a reference (Navigation Property) from the CountryId property of my Complex Type to the Id property of my Country entity.

I'm I going about this the wrong way or is this something that I can't do with the designer??...

Another option I have is just creating an Address entity, but it just doesn't sound right to me.


回答1:


No, you can't do this, because it goes against the idea of what complex types and navigation properties are. Complex types have value semantics, rather than reference identity. Navigation properties are first-class entities and have reference semantics. Therefore, they cannot be part of a complex type. As it seems you've discovered, the solution is to partition the parts with value semantics into the complex type, and add it to an entity containing the navigation properties you require.




回答2:


Ok,

It seems like the current version of the Entity Framework doesn't support a Navigation Property or foreign key within a Complex Type.

The other sensible option is to create a separate Address Entity, which will have all of the foreign keys it needs, and then create Navigation Properties within all my other entities.



来源:https://stackoverflow.com/questions/1614703/how-do-i-add-a-navigation-property-for-a-entity-framework-complex-type

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