I have a list of movies
List<Movie> MovieList
and I have a list of selected categories
List<string> SelCat
And I’ll say that I want to select from the list of films where it corresponds to 2 categories, for example, SQL statements:
SELECT * FROM MovieList WHERE MovieList.Category = 'Action' AND MovieList.Category = 'Drama'
I can get closer to linq like this:
var q = (from b in MovieList where b.Categories.Any(p=> SelCat.Contains(p)) select b);
But it acts like an OR request, not an AND. I want him to choose all the films in which there is a category of action and drama.
BTW: Movie.Categories is a list of strings . And Movie.Categories should contain elements in SelCat .
How to achieve this with Linq for objects?
source
share