Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Get all users with a specific role in ASP.NET Core 2.0

$
0
0

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!


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>