[英]Linq Query to Search “Many” in one to many relationship
大家好,我有EF类别的Book和Comments。
一本书可以有很多评论。
如何搜索带有包含搜索文本的任何注释的书?
到目前为止,我的方法看起来像这样...
public IEnumerable<Book> Search(string commentText)
{
IQueryable<Book> books = _context.Books;
books.Where() //need to filter by commentText here
return books;
}
尝试这个:
books.Where(a=>a.Comments.Any(b=>b.CommentText.Contains(commentText)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.