简体   繁体   English

我如何将EDMX文件中的联结表替换为多对多关系?

[英]How I alternative junction table in EDMX file to many to many Relation between two table in edmx file?

I have three table in SQL database such as table Person has relation one to many to table member and number has one to many relation to table member .that means member table in this design is junction table and i want do many to many relation between person table and number table for removing member table .but i cant because when i do relation between person and number in my EDMX file and Generate the EDMX model to SQL database .the sql database creates a table between person table and number table has two field such as personId and numberId. 我在SQL数据库中有三个表,例如表Person与表成员具有一对多关系,而number与表成员具有一对多关系。这意味着此设计中的成员表是联结表,我想在人与人之间进行多对多关系表和数字表以删除成员表。但是我不能,因为当我在EDMX文件中进行人和数字之间的关系并将生成的EDMX模型生成到SQL数据库时。sql数据库在人表和数字表之间创建了一个表,该表具有两个字段作为personId和numberId。 i want add Some field to junction table that removed between two tables.for example i need firstname or last name in junction table that i removed .how i alternative a junction table to many to many relation between two table in my EDMX file that the junction table has more field? 我想向在两个表之间删除的联结表中添加一些字段。例如,我需要删除的联结表中的名字或姓氏。我如何将联结表替换为我的EDMX文件中两个表之间的多对多关系表有更多字段?

If you are using database first simply add all columns you need in junction table and update model from database. 如果首先使用数据库,则只需在联结表中添加所需的所有列,然后从数据库更新模型。 EDMX will contain a new Member entity. EDMX将包含一个新的Member实体。

If you are using model first you cannot use many to many relation between Person and Number . 如果首先使用模型,则不能使用PersonNumber之间的多对多关系。 You must model three entities - Person , Member and Number with the same relations you expect in the database. 您必须对三个实体PersonMemberNumber进行建模,并在数据库中建立相同的关系。 Once you use generated database from model you will get the database you expect. 使用模型中生成的数据库后,您将获得所需的数据库。

Many-to-many relation with hidden junction table in EDMX is only for scenarios where you have a real junction table without any additional data columns. EDMX中的隐藏联结表与多对多关系仅适用于您拥有真实联结表而没有任何其他数据列的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM