Consider the database schema in the picture.
![]()
I need a linq-to-entities statement that will retrieve authors and their respective books grouped by author. For example, I want to display something as follows:
authorName8 bookTitle27 bookTitle35 bookTitle62 authorName37 bookTitle9 bookTitle51
An additional constraint is the oject of grouped items has to be returnable by a method.
Can anybody formulate join and group-by statement (a) ordered by author name, (b) ordered by author name and book title?
You didn’t mention which version of EF you are using, or whether you need to filter the authors by some condition, or filter the books by some condition. A general query that will fetch everything will look like this:
If you want to filter the book collections, you will have to write a more elaborate query though.