I have a piece of code which contains nested ANY. When it gets to that part it throws classic exception about converting to client side evaluation. I would like to know if there is a way to rewrite the code and avoid converting this query to client side evaluation. Here is the code:
var query = _assignmentRepository
.GetAll()
.Include(x => x.AssignmentUsersAssigned).ThenInclude(y => y.User)
.WhereIf(input.UserIds.Any(), x => input.UserIds.Contains(x.CreatorUserId.Value) || input.UserIds.Any(y => x.AssignmentUsersAssigned.Any(z => z.UserId == y)));
Input.UserIds is of type List long. Any ideas?
Rewrite this part:
input.UserIds.Any(y => x.AssignmentUsersAssigned.Any(z => z.UserId == y))
in this way:
x.AssignmentUsersAssigned.Any(z => input.UserIds.Contains(z.UserId))
Rewrite this part:
input.UserIds.Any(y => x.AssignmentUsersAssigned.Any(z => z.UserId == y))
in this way:
x.AssignmentUsersAssigned.Any(z => input.UserIds.Contains(z.UserId))
That does it, thanks!
Most helpful comment
Rewrite this part:
input.UserIds.Any(y => x.AssignmentUsersAssigned.Any(z => z.UserId == y))in this way:
x.AssignmentUsersAssigned.Any(z => input.UserIds.Contains(z.UserId))