如何在Entity Framework设计器中建立多对多的关系 [英] How to set up a many-to-many relationship in Entity Framework designer thingy
问题描述
我不知道如何设置多对多关系!我从数据库中更新了模型,但是我得到了一个与实体对应的新实体的两个一对多关系(仅包含外键和自己的主键)。
到目前为止,所有尝试通过点击实体和关系进行此操作都失败了。任何人都可以给我一个指针?
你的连接表必须是MS称为纯连接表' - 它必须包含只有两个外键,而不其他列。在您的情况下,这意味着您必须删除主键列。
I'm an NHibernate developer trying to give Entity Framework a shot in a hobby project. I'm used to specifying mapping data in code using Fluent NHibernate. Pardoning Microsoft's belief that developers shouldn't be allowed to write code, I'm trying to create my mappings using the Entity Framework's visual designer surface (which you get by opening the .edmx file in Visual Studio).
I have no idea how to set up a many-to-many relationship! I have 'updated the model' from the database, but I get two one-to-many relationships with a new entity corresponding to the junction table (which contains only foreign keys and its own primary key).
So far, all attempts at working this out by clicking on the entities and relationships and such have failed. Can anyone give me a pointer?
Your junction table must be what MS calls a 'pure join table' - it must contain only the two foreign keys, and no other columns. In your case, that means you must delete the primary key column.
这篇关于如何在Entity Framework设计器中建立多对多的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!