Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Identity(MVC5)中为数据访问层中的每个用户获取用户角色?_C#_Linq_Asp.net Mvc 5_Asp.net Identity - Fatal编程技术网

C# 如何在Identity(MVC5)中为数据访问层中的每个用户获取用户角色?

C# 如何在Identity(MVC5)中为数据访问层中的每个用户获取用户角色?,c#,linq,asp.net-mvc-5,asp.net-identity,C#,Linq,Asp.net Mvc 5,Asp.net Identity,应用程序是基于c#的MVC5身份。如前所述,AspNetUserRoles未在EDMX中填充。当然不能使用LINQ查询它 在数据访问层中,具有函数GetAllUsers()。对于每个用户,需要获取其在AspNetUserRoles表中映射的角色。能够获取所有用户,但没有其角色。为每个用户获取角色是否热门?AspNetUserRoles是一个映射表(多对多),因此它不是在EDMX中生成的(根据设计,它没有主键) 您可以使用导航属性获取用户角色: user.Include(u => u.Rol

应用程序是基于c#的MVC5身份。如前所述,
AspNetUserRoles
未在EDMX中填充。当然不能使用LINQ查询它


在数据访问层中,具有函数
GetAllUsers()
。对于每个用户,需要获取其在
AspNetUserRoles
表中映射的角色。能够获取所有用户,但没有其角色。为每个用户获取角色是否热门?

AspNetUserRoles
是一个映射表(多对多),因此它不是在EDMX中生成的(根据设计,它没有
主键

您可以使用
导航属性
获取用户角色:

user.Include(u => u.Roles); // only need if lazy loading disabled
var roles = user.Roles; 

为我工作。dbContext.AspNetUsers.Include(s=>s.AspNetRoles)