实体框架 - 添加导航属性手动 [英] Entity Framework - Add Navigation Property Manually
问题描述
我从数据库中生成一个实体框架模型(4.0)。我没有设计的数据库,并没有对架构的任何控制,但有没有外键约束定义的几桌,但有定义的隐含关系。
I generated an Entity Framework Model (4.0) from my database. I did not design the database and do not have any control over the schema, but there are a few tables that do not have foreign key constraints defined, but there is an implicit relationship defined.
例如:
我有以下几列的表中调用的人:
GenderID
RaceID
I have a table called People that has the following columns: GenderID RaceID
有两个性别和种族的表,但没有在人民表中没有外键。
There are tables for both Gender and Race but there is no foreign key in the People table.
当我导入模型并没有添加导航属性这些关系。我尝试手动添加它,但是从作用和角色都被禁止。我不知道如何添加关系喽。我该怎么做呢?
When I imported the model it did not add Navigation Properties for these relationships. I tried to add it manually but From Role and To Role are disabled. I'm not sure how to add the relationship myself. How do I do this?
推荐答案
是的 - 它不是那么简单。
Yup - it's not that straightforward.
下面就是你要做的:
1 - 右键单击设计师,添加 - > 协会
1 - Right click on the designer, Add -> Association
2 - 设置的关联和基数(人民*。1性别,人民*。1赛)
2 - Setup the association and cardinalities (People *..1 Gender, People *..1 Race)
3 - 走进在模型浏览器 - > 协会
3 - Go into the Model Browser -> Associations
4 - 鼠标右键点击你新建的关联,点击属性
4 - Right click on your newly created associations, click Properties
5 - 在这里你需要设置的关键和级联选择的端点。确保你得到了正确的终点。您还可以设置一个参照约束在这里为您导航隐含属性。
5 - Here you need to setup the endpoints for the key and cascade options. Make sure you get the endpoints correct. You can also setup a referential constraint here for your implicit navigational property.
6 - 导航属性相关的表/字段映射
6 - Map the navigational property to the relevant tables/fields.
7 - 验证模型,手指交叉
7 - Validate your model, cross your fingers.
希望这有助于。
这篇关于实体框架 - 添加导航属性手动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!