0

How do i filter users by role id in asp.net.identity 3.0?

I can't navigate to Roles (x => x.Roles) anymore.

Prior version (Asp.net.identity 2.0)

I had been filtering users by role id as following

List<ApplicationUser> adminUsers = _context.Users.Where(x => x.Any(y => y.RoleId == testAdminId || y.RoleId == adminId)).ToList();
simbada
  • 940
  • 4
  • 24
  • 43
  • Why can't you navigate to Roles? Do you not have the relationship in your models? – Brad Aug 21 '17 at 05:03
  • @Brad have a look at this post to get answer to your question. Please let me know what you understand becuase I still couldn't find the way. https://stackoverflow.com/questions/39946711/get-user-with-assigned-roles – simbada Aug 21 '17 at 05:42
  • 1
    Does `_context.Users.Include(x => x.Roles).ThenInclude(x => x.Role).Where(x => x.Roles.Any(y => y.RoleId == adminId)).ToList()` work? – Brad Aug 21 '17 at 06:33
  • @Brad, thanks i shall give a try soon and let you know the outcome. – simbada Aug 21 '17 at 17:32
  • @Brad it does not work. Basically i am using AspNetCoreIdentity 3 and i think they have taken off Roles navigation property from Users. – simbada Aug 24 '17 at 18:43
  • Can you add the relationship in your own `ApplicationUser` class? – Brad Aug 25 '17 at 04:50
  • The navigation properties have been removed in .NET Core 2.0. See https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x under the heading **Add IdentityUser POCO Navigation Properties**. I can post this as an answer if you like. – Brad Aug 31 '17 at 11:05

0 Answers0