Entity Framework Core 1.0 -Lazy Loading and Eager Loading

EF Core 1.0 does not support automatic lazy loading and eager loading related objects in the same way that EF6 did. Lazy loading does make data access easier and it cuts the code you have to write to reach that data significantly,  so its good to see that it is still listed as a priority item here on EF’s  Roadmap.

Until then, the way to eager load related objects, is by the .Include() and .ThenInclude() methods.  Here are two examples.


var leagues = db.Leagues
            .Include(l => l.Teams)
            .ThenInclude(t => t.Players)
            .ToList();
  
var leagues = from d in db.Leagues.Include(l => l.Teams) select d;
    
Advertisements

One thought on “Entity Framework Core 1.0 -Lazy Loading and Eager Loading

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s