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.
Below is my linq query.
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",
"email": "[email protected]",
"roles": [
"Supplier",
"Assistant Buyer"
]
},
{
"id": 1,
"userName": "Admin",
"email": "[email protected]",
"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.
Sagar MaldePosted Mar 9, 2020, 1:15 AM
Michael SeeryPosted Mar 3, 2020, 2:01 AM
Jignesh KumarPosted Mar 2, 2020, 9:30 AM
Michael SeeryPosted Mar 2, 2020, 6:54 AM
Ravi PatelPosted Mar 2, 2020, 6:08 AM
Michael SeeryPosted Mar 2, 2020, 5:11 AM
Ravi PatelPosted Mar 2, 2020, 4:58 AM