I have a problem with query which I want to produce.
var ratings = repository.GetAll<Rating>()
.AsNoTracking()
.Select(e => new RatingGridDto()
{
Id = e.Id,
Sites = e.Locations.Select(x => x.Name).ToList(),
});
// this filter will come from frontent
var mockedFilter = new List<string>()
{
"LosAngeles","Vienna","Praha"
};
// ratings = IQueryable of course
// case 1
ratings = ratings.Where(e => mockedFilter.AsEnumerable().All(f => e.Sites.Contains(f)));
// case 2
ratings = ratings.Where(e => mockedFilter.All(f => e.Sites.Contains(f)));
// case 3
ratings = ratings .Where(e => mockedFilter.All(x => e.Sites.Any(y => y == x)));
// case 4
foreach (var filter in mockedFilter)
{
ratings = ratings .Where(e => e.Sites.Contains(filter));
}
Only method from case 4 works, rest of them are throwing error that EF is not able to translate it to SQL ...
Anyone know why this problem occures and why when we will use foreach all works?