实体框架外键映射到同一个表

实体框架外键映射到同一个表

本文介绍了实体框架外键映射到同一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不是this帖子虽然题目很相似。我使用EF4与MSSQL防爆preSS 2008 R2上的VS2010。

This is not a duplicate of this post although the title is very similar. I am using EF4 with MSSQL Express 2008 R2 on VS2010.

我的架构的简化版本如下:

A simplified version of my schema is as follows:

Table [Team]:
 Id (PK)
 Member1
 Member2

Table [Person]:
 Id (PK)
 FirstName

[队伍] .Member1和[队伍] .Member2外键指向[人] .ID。

[Team].Member1 and [Team].Member2 are foreign keys pointing to [Person].Id.

在生成通过VS2010中的.edmx,在[组]导航性能成为人和PERSON1尽管对FKS给予不同的名称里面SQLServer的。

When generating the .edmx via VS2010, the navigation properties under [Team] become "Person" and "Person1" despite giving distinct names to the FKs inside SQLServer.

是否可以强制的.edmx生成器识别SQL Server中我FK的名字呢?我想这些名字是Member1Person和Member2Person,例如,所以我没有手动手动重命名。如果没有,什么是preferred的方式来重新设计表格/ FKS完全绕过这个?谢谢你。

Is it possible to force the .edmx generator to recognize my FK names in SQL Server? I'd like these names to be Member1Person and Member2Person, for example, so I don't have to manually rename them by hand. If not, what is the preferred way to redesign the tables/FKs to bypass this altogether? Thank you.

推荐答案

我也有过类似的问题,但我认为,问题的答案是,你只需要重命名Navagation属性为你想要的。该实体Framwork设计师将永远让你改变对事物的概念端属性名称。

I have had a similar issue but I believe the answer to the question is you simply have to rename the Navagation property to what you want. The Entity Framwork designer will always keep you changes to the property names on the Conceptual side of things.

这篇关于实体框架外键映射到同一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:46