Reputation: 9234
Hey guys I have EF classes of Book and Comments.
A book can have many comments.
How can I search for a book with any comment that contains my search text?
My method looks like this as of now...
public IEnumerable<Book> Search(string commentText)
{
IQueryable<Book> books = _context.Books;
books.Where() //need to filter by commentText here
return books;
}
Upvotes: 1
Views: 2336
Reputation: 82913
Try this:
books.Where(a=>a.Comments.Any(b=>b.CommentText.Contains(commentText)));
Upvotes: 5