How do I filter a list containing another list in C#?

Viewed 116

I have two classes connected via a one-to-many relationship:

public class Movie
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Synopsis { get; set; }
    public IList<Tag> Tags { get; set; }
}

public class Tag
{
    public int Id { get; set; }
    public string Name { get; set; }
}

How do I find all movies containing a given string? I manage as long as I do not dive into the tags:

var result = movies.Where(m => m.Title.Contains(searchString) |
                               m.Synopsis.Contains(searchString));

Here is some pseudo code, only working in my dreams:

var result = movies.Where(m => m.Title.Contains(searchString) |
                               m.Synopsis.Contains(searchString) | 
                               m.Tags.Name.Contains(searchString)); 
                              // Cannot access Name property of Tags like this

What is the right way to do it?

1 Answers
Related