Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2019 18:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Eager loading with EF Core
public void GetBooksWithEagerLoading()
var books = _booksContext.Books
.Where(b => b.Publisher.StartsWith("Wrox"))
.Include(b => b.Chapters)
.Include(b => b.Author)
.Include(b => b.Reviewer)
.Include(b => b.Editor);
foreach (var book in books)
foreach (var chapter in book.Chapters)
Console.WriteLine($"{chapter.Number}. {chapter.Title}");
Console.WriteLine($"author: {book.Author?.Name}");
Console.WriteLine($"reviewer: {book.Reviewer?.Name}");
Console.WriteLine($"editor: {book.Editor?.Name}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment