实体框架 4 - 对所有多对多关系使用单个映射表
我想通过数据库中的单个表映射所有多对多关系。 这意味着我有许多具有各种多对多关系的表(实体)。我不想为每个关系都有一个单独的映射表,而是使用一个具有以下列的“主映射”表:End1Id & End2Id。
不要问为什么;)这是我的客户所要求的...
我将如何在模型设计器中进行设置,或者我是否必须直接编辑 edmx xml...或者这是不可能的?
感谢您的帮助!
I would like to map all many-to-may relations through a single table in my database.
Meaning that I have numerous tables (entities) that have various many-to-many relations. Instead of having a separate mapping table for every relation I would like to use one "master mapping" table having to columns: End1Id & End2Id.
Don't ask why ;) It's required by my customer...
How would I set this up in the model designer, or do I have to edit the edmx xml directly....or is it just not possible?
Thanx for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,您不能使用显式外键,因为这样的表通常至少有三行:
因此,您可以只在 EF 中创建一个表,但它也不会与其他表建立连接,并且您必须手动执行联接。
In such a scenario you can't have explicit foreign keys, because a table like this normally has at least three rows:
Because of that, you can just create a table in EF, but it will also have no connections to other tables and you will have to do the joins manually.
您需要手动设置此主映射表。设计师不会自动为你做这件事。
但是,如果您正在寻找非规范化实体,那么最好在 DB 级别而不是 EF/代码级别对这些实体进行非规范化。
You would need to set this Master Mappings table manually. The designer doesn't do it for you automatically.
However - if denormalized entities are what you are looking for, better have those denormalized in DB level rather than in EF/code level.