【发布时间】:2016-02-19 14:29:47
【问题描述】:
我正在使用 Microsoft Identity,我需要与 IdentityUser 和 IdentityRole 创建多对多关系。我将属性作为public virtual ICollection<Role> IdentityRoles { get; set; } 添加到IdentityUser 类和public virtual ICollection<User> IdentityUsers { get; set; } 到IdentityRole,但迁移添加了一个名为RoleUsers 的表。
我想将现有的UserRoles 表用于多对多关系。
我该如何创作?
【问题讨论】:
-
您确定需要多对多关系吗?还是您只对以下内容感兴趣:1. 与某个用户关联的角色和 2. 与某个角色关联的所有用户?
-
关系已经是多对多的开箱即用(因此是现有的联结表)。
-
我确信我需要多对多关系。存在关系,但 IdentityRole Users 属性返回 ICollection
并且 IdentityUser Roles 属性返回 ICollection 。我想调用 IdentityUser 中的所有角色和 IdentityRole 中的所有用户。
标签: asp.net-mvc asp.net-identity