简体   繁体   English

实体框架EDMX关系映射表

[英]Entity Framework EDMX Relationship Mapping Table

I have a users table and a roles table. 我有一个用户表和一个角色表。
To link the two together I have created a UsersInRoles table which has a foreign key to the Users' UserId and another foreign key to the Roles' RoleName. 为了将两者链接在一起,我创建了一个UsersInRoles表,该表具有一个指向User's UserId的外键和另一个Roles'RoleName的外键。

However, when I generate an EDMX from the database instead of a separate table for UsersInRoles, an association is created instead. 但是,当我从数据库而不是为UsersInRoles生成单独的表时生成EDMX时,会创建一个关联。 Should I be using this association or should I try to figure out how to get the UsersInRoles table to be generated? 我应该使用这种关联还是应该尝试弄清楚如何生成UsersInRoles表?

This is the normal behavior of Entity Framework. 这是实体框架的正常行为。 The tables used to create n - n relationships are not created in the model as entities(The tables used as a middle table to create a relationship between two tables). 用于创建n-n关系的表在模型中未作为实体创建(这些表用作在两个表之间创建关系的中间表)。

Instead you will observe an n to n relationship between Users and Roles entities. 相反,您将观察到UsersRoles实体之间的n对n关系。

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

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