Imagine three entities (Customer, Book, Author) related like this:
A Customer has many Books
A Book has one Author
I use that data to print a report like this:
Customer: Peter
Book: To Kill a Mockingbird - Author: Harper Lee
Book: A Tale of Two Cities - Author: Charles Dickens
Customer: Melanie
Book: The Hobbit - Author: J. R. R. Tolkien
When I query for Customers I get, as expected, a bunch of queries of the following nature
- A query to get the Customers
- A query per Customer to get his Books
- A query per Book to get its author
I can reduce the number of queries by including the books like so:
var customers = db.Customers.Include(c => c.Books);
But I don't know how to load the third level (Author). How can I do that?