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

问题描述

这不是与虽然标题非常相似。我在VS2010上使用带有MSSQL Express 2008 R2的EF4。

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

[Team] .Member1和[Team] .Member2是指向[Person] .Id。

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

当通过VS2010生成.edmx时,[Team]下的导航属性将变为Person和Person1,尽管为SQLServer中的FK提供不同的名称。

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,所以我不必手动重命名它们。如果没有,重新设计桌子/ FK以绕过这个方案的首选方式是什么?谢谢。

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财产到你想要的实体框架设计师将始终保持对事物概念方面的属性名称的更改。

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-18 19:02