如何为实体框架复杂类型添加导航属性 [英] How do I add a navigation property for a Entity Framework Complex Type

查看:104
本文介绍了如何为实体框架复杂类型添加导航属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VS2010 Beta 2,我有一个名为地址的复合类型,具有以下属性:

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


  • 街道

  • 城市

  • CountryId

我的模型中定义了一个国家/地区实体,但我似乎找不到从复合类型的 CountryId 属性添加引用(导航属性)的方法到国家/地区实体的 ID 属性。

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??...

另一个选项是创建一个Address实体,但它听起来不正确对我来说

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

推荐答案

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.

这篇关于如何为实体框架复杂类型添加导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆