TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Michael Seery
NA
85
10.4k
Filter joined string array
Mar 2 2020 4:25 AM
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.
Reply
Answers (
7
)
How to find out 2nd or nth highest salary?
change SQL to linq