Linq查询在一对多关系中搜索“多个”

时间:2011-04-12 17:29:52

标签: c# linq entity-framework linq-to-entities

嘿伙计们,我有EF课程和评论。

一本书可以有很多评论。

如何搜索包含我的搜索文本的任何评论的图书?

我的方法截至目前为止......

public IEnumerable<Book> Search(string commentText)
{

     IQueryable<Book> books = _context.Books;

     books.Where() //need to filter by commentText here

     return books;

}

1 个答案:

答案 0 :(得分:5)

试试这个:

books.Where(a=>a.Comments.Any(b=>b.CommentText.Contains(commentText)));
相关问题