S
shapper
Hello,
I need to select all users which User.Roles contain a role with Id =
RoleId:
return _context.Users.Select(u => new Models.User {
Approved = u.Approved,
// ...
}).Where(u => u.Roles.Contains(r => r.Id == RoleId)).AsQueryable
();
I get an error on Contains as follows:
Cannot convert lambda expression to type 'Domain.Models.Role' because
it is not a delegate type
I don't have the entire role, Id and Name, I have only its Id (RoleId)
I use the following that compiles:
}).Where(u => u.Roles.Count(r => r.Id == RoleId) > 0).AsQueryable();
But I am not sure if this is the way to do it ...
How should I implement this.
Thanks,
Miguel
I need to select all users which User.Roles contain a role with Id =
RoleId:
return _context.Users.Select(u => new Models.User {
Approved = u.Approved,
// ...
}).Where(u => u.Roles.Contains(r => r.Id == RoleId)).AsQueryable
();
I get an error on Contains as follows:
Cannot convert lambda expression to type 'Domain.Models.Role' because
it is not a delegate type
I don't have the entire role, Id and Name, I have only its Id (RoleId)
I use the following that compiles:
}).Where(u => u.Roles.Count(r => r.Id == RoleId) > 0).AsQueryable();
But I am not sure if this is the way to do it ...
How should I implement this.
Thanks,
Miguel