ste*_*776 1 c# linq linq-to-entities entity-framework
嘿伙计们,我有EF课程和评论.
一本书可以有很多评论.
如何搜索包含我的搜索文本的任何评论的图书?
我的方法现在看起来像这样......
public IEnumerable<Book> Search(string commentText)
{
IQueryable<Book> books = _context.Books;
books.Where() //need to filter by commentText here
return books;
}
Run Code Online (Sandbox Code Playgroud)
试试这个:
books.Where(a=>a.Comments.Any(b=>b.CommentText.Contains(commentText)));
Run Code Online (Sandbox Code Playgroud)