I'm just getting started with porting a application from ASP.NET MVC 5 to ASP.NET Core 2.0 (with EF Core and Identity). All has been going smooth, but I've ran into a problem that I can't seem to find an answer to.
What I want to do is simply to fetch all users in a database, based on the role they are assigned (Admin, User, etc.).
This was simple in MVC 5 where I was just using:
_db.UserCompany.Where(x => x.User.Roles.Any(s => s.RoleId == adminRole.Id)
However, with .NET Core / Entity Framework Core I don't seem to be able to navigate through the User -> Role anymore.
So my question is if there is a already implemented way in Identity/EF Core to achieve what I want? Or is it necessary to implement a custom solution?
Thanks in advance!
For me, User Manager was the answer
private readonly UserManager<ApplicationUser> _userManager;
_userManager.GetUsersInRoleAsync("myRole").Result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With