I'm doing a filter and I need all the values that has for example (rock = id 3 and jazz = id 6)
How can I do that in LINQ ?
I'm doing this but this gives first the one with rock and the with jazz....
private IQueryable<Performance>addGenreFilterToPerformanceQuery(IQueryable<Performance> query, List<int> genreFilters)
{
if (genreFilters != null)
{
foreach (var genreFilter in genreFilters)
{
return query.Where(p => p.Artist.Genres.Any(g => genreFilters.Contains(g.Id)));
}
}
return query;
}
Any suggestions?
The
foreach
isn't really doing anything. If you want the query to match all genre ids rather than any, useAll
, notAny
: