实体框架外键映射到同一表
这不是 的重复项这篇文章虽然标题非常相似。我在 VS2010 上使用 EF4 和 MSSQL Express 2008 R2。
我的架构的简化版本如下:
Table [Team]:
Id (PK)
Member1
Member2
Table [Person]:
Id (PK)
FirstName
[Team].Member1 和 [Team].Member2 是指向 [Person].Id 的外键。
通过 VS2010 生成 .edmx 时,[Team] 下的导航属性变为“Person”和“Person1”,尽管为 SQLServer 内的 FK 提供了不同的名称。
是否可以强制 .edmx 生成器识别我在 SQL Server 中的 FK 名称?例如,我希望这些名称为 Member1Person 和 Member2Person,这样我就不必手动重命名它们。如果不是,重新设计表/FK 以完全绕过这个问题的首选方法是什么?谢谢。
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 and [Team].Member2 are foreign keys pointing to [Person].Id.
When generating the .edmx via VS2010, the navigation properties under [Team] become "Person" and "Person1" despite giving distinct names to the FKs inside SQLServer.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的问题,但我相信问题的答案是您只需将导航属性重命名为您想要的即可。实体框架设计器将始终让您在概念方面对属性名称进行更改。
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.