-
-
Save christiannagel/775e68a33388e0c9f2d48144f48e4964 to your computer and use it in GitHub Desktop.
Eager loading with EF Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{ | |
Console.WriteLine(book.Title); | |
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