hanesjw
hanesjw

Reputation: 2584

Searching in side an object's list of objects using lambda expressions?

I have 2 tables; they have a many-to-many relationship. One is called Blog the other is Tag.

A Blog can contain a List of Tag objects. How can I go about getting all blogs that have a passed in tag name using lambda expressions?

Thanks!

Upvotes: 2

Views: 734

Answers (1)

Ahmad Mageed
Ahmad Mageed

Reputation: 96487

Assuming the Tag table has a Name property, it might be something like this (roughly):

string tagName = "tag-to-search-for";
var query = Blog.Where(blog => blog.Tag.Any(tag => tag.Name == tagName));

Upvotes: 3

Related Questions