导航属性上加入的实体框架表 [英] Navigation Properties on Join Tables in Entity Framework

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

问题描述

所以,我有一个表在我的SQL数据库:

So I have a table in my SQL database:

CompanyRelationships
--------------------
ID
CompanyID
RelatedCompanyID
PermissionGroupID

其中定义,当一个公司能够访问它的记录给另一家公司。而CompanyID是授予访问该公司时,RelatedCompanyID是获取访问公司。

Which defines when a company allows access to it's records to another company. The "CompanyID" is the company that is granting access, the "RelatedCompanyID" is the company that is getting the access.

是的,两个记录可能存在相同的两家公司(其他各授权访问)

Yes, two records could exist for the same two companies (each granting access to the other)

现在的问题是,当我生成的数据库实体模型(在Visual Studio 2010),导航性能我得到的是不完全有益至于哪个是哪个。我得到的:

The problem is when I generate the entity model from the db (In Visual Studio 2010), the navigation properties I get are not exactly helpful as to which is which. I get:

Company
Company1
UserGroup

用户组当然是显而易见的,但我想知道哪些公司引用是,因为这是一种非常重要的。我敢肯定,我可以测试它找出来,但我会每次我从数据库中再生的时间来重新测试,以确保。有没有办法强制导航属性的命名是该领域的FK,而不是它与实体?

UserGroup is of course obvious, but I would like to know which company reference is which, as that is kind of important. I'm sure I could test it and find out, but then I would have to retest to be sure every time I regenerated from the database. Is there a way to force the naming of the navigation property to be that of the FK field and not the entity it is linked to?

推荐答案

您总是可以点击导航属性的实体的模型浏览器,并期待在属性窗口。该窗口会显示协会名称(在数据库中添加表之间的关系时创建)。一旦你确定了关系,你总是可以重命名的导航属性名称为您所选择的名称。

You Could always Click on the Navigational Property on the Entity in the Model Browser, and look up the Properties Window. The Window Shows the Association Name (created when adding Table relationships in database). Once you identify the Relation, you could always rename the Navigational Property Name to a name of your choice.

例如,点击公司1中的实体图导航属性会告诉你有关系的名字为Company_Id_to_Related_Company_Id(或任何名称)。一旦你知道这意味着什么,你可以重命名的导航属性设置为一个有意义的名称,如MasterCompany。

Example, Clicking "Company1" Navigational property in the Entity Diagram would show you a relationship name as "Company_Id_to_Related_Company_Id" (or whatever the name is). Once you know what it means, you can rename the Navigational Property to a meaningful name such as "MasterCompany".

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

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