Reputation: 3234
I have the following method being used to get all users by a role and it was working fine until version 2.0 was released. Has something changed? Role no longer exists, only RoleId but that isn't useful as I need to access by name... appears Microsoft removed/moved this to a different class? Can't find it anywhere though.
public List<ApplicationUser> GetUsersByRole(string userRole)
{
return (_accountRepository.Get.SelectMany(user => user.Roles, (user, role) => new { user, role })
.Where(x => x.role.Role.Name == userRole).Select(x => x.user)).ToList();
}
the Role object in x.role.Role.Name no longer resolves.
Upvotes: 1
Views: 92
Reputation: 28200
The Role/User navigation properties on IdentityUserRole
were removed in version 2.0, a workaround would be to write your own linq query at the appropriate db context specific layer to get the list of users in a particular role. Longer term, we will be adding a GetUsersInRole
method to RoleManager
(tentatively should be in 2.1).
Upvotes: 1