Search code examples
c#linq

linq where list contains any in list


Using linq, how can I retrieve a list of items where its list of attributes match another list?

Take this simple example and pseudo code:

List<Genres> listofGenres = new List<Genre>() { "action", "comedy" });   
var movies = _db.Movies.Where(p => p.Genres.Any() in listofGenres);

Solution

  • Sounds like you want:

    var movies = _db.Movies.Where(p => p.Genres.Intersect(listOfGenres).Any());