【发布时间】:2021-04-07 08:36:37
【问题描述】:
在我的项目中,每个用户都有一个或多个组,每个组都有一个或多个角色 在用户登录后,我想使用实体框架 3 获取该用户的角色。 这些是我拥有的模型。
用户模型
public class User
{
public User()
{
userGroups = new List<UserGroup>();
}
public int Id { get; set; }
[Display(Name = "UserName")]
[Required]
public string Username{get;set;}
public ICollection<UserGroup> userGroups{get;set;}
}
组模型
public class Group
{
public int Id { get; set; }
[Display(Name = "groupName")]
[Required]
public string groupName { get; set; }
public ICollection<RoleGroup> roleGroups { get; set; }
public ICollection<UserGroup> userGroups { get; set; }
}
用户组模型
public class UserGroup
{
public int userId{get;set;}
public User user{get;set;}
public int groupId{get;set;}
public Group group{get;set;}
}
榜样
public class Role
{
public int Id{get;set;}
public string roleName{get;set;}
public string roleDescription{get;set;}
public ICollection<RoleGroup> roleGroups{get;set;}
}
角色组模型
public class RoleGroup
{
public int RoleId{get;set;}
public Role role{get;set;}
public int groupId{get;set;}
public Group group{get;set;}
}
我想要的是使用 ID 获取特定用户的所有角色。
提前致谢。
【问题讨论】:
标签: .net asp.net-mvc entity-framework asp.net-core .net-core