How to get all users in Role (Microsoft ASP.NET Identity EntityFramework 2.0.0-beta1)?

前端 未结 3 1328
我在风中等你
我在风中等你 2020-12-09 20:57

I just updated to ASP.NET Identity EntityFramework 2.0.0-beta1 and got a compilation errors for my Roles classes. Maybe somebody can give me some clue how to get all users f

3条回答
  •  甜味超标
    2020-12-09 21:42

    The accepted answer returns CustomUserRoles. If you are looking for the list of ApplicationUsers, try:

    public IList GetApplicationUsersInRole(string roleName)
    {
        var selectedUserIds = from role in roleManager.Roles
                              where role.Name == roleName
                              from user in role.Users
                              select user.UserId;
        // this _users comes from the ApplicationDbContext.ApplicationUser
        return _users.Where(applicationUser => selectedUserIds.Contains(applicationUser.Id)).ToList();
    }
    

提交回复
热议问题