I have a linq query that returns all users with their identity roles.
I am able to filter the results by using where claused however, I am unable to figure out how to filter based on a role name.
var userList = (from user in _context.Users orderby user.UserName
select new UserForDetailDto
{
Id = user.Id,
UserName = user.UserName,
Email = user.Email,
Roles = (from userRole in user.UserRoles
join role in _context.Roles
on userRole.RoleId
equals role.Id
select role.Name).ToArray()
}).AsQueryable();
The below is sample of what is returned.
[
{
"id": 6,
"userName": "Adam",
"roles": [
"Supplier",
"Assistant Buyer"
]
},
{
"id": 1,
"userName": "Admin",
"roles": [
"Administrator"
]
}
]
I am able to filter the userList using a where clause such as the one below.
userList = userList.Where(u => u.UserName.ToLower().Contains(userParams.UserName.ToLower()));
I would like to be able to add a where clause to the role.Name string array.
Where roles contains 'Supplier' for example.
Any help would be appreciated.