diff --git a/EntityFrameworkCore.Console/Program.cs b/EntityFrameworkCore.Console/Program.cs index 8052a50..9d79533 100644 --- a/EntityFrameworkCore.Console/Program.cs +++ b/EntityFrameworkCore.Console/Program.cs @@ -15,6 +15,23 @@ context.Database.EnsureCreated(); // Rather than raise: "System.InvalidOperationException: Sequence contains no elements." // var firstCoach = await context.Coaches.FirstOrDefaultAsync(); +async Task EagerLoadingExample() +{ + var leagues = await context.Leagues + .Include(l => l.Teams) + .ThenInclude(t => t.Coach) + .ToListAsync(); + + foreach (var league in leagues) + { + Console.WriteLine($"League - {league.Name}"); + foreach (var team in league.Teams) + { + Console.WriteLine($"* {team.Name} - {team.Coach.Name}"); + } + } +} + async Task InsertRelatedData() { // Insert record with a Foreign Key.