开发者

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

开发者 https://www.devze.com 2022-12-18 12:13 出处:网络
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 obje开发者_如何学Ccts. How can I go about getting all blogs that have a p

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 obje开发者_如何学Ccts. How can I go about getting all blogs that have a passed in tag name using lambda expressions?

Thanks!


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));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号