O'Reilly logo

Fluent Entity Framework by Rebecca M. Riordan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lazy loading

When you execute a query, Entity Framework only loads the data you explicitly request. Just because a Recipe has Ingredients or RecipeSteps, it doesn’t assume that you’re going to want that data, so it doesn’t fetch it. So what happens if you ask for something that hasn’t been loaded by the query?

LAZY LOADING (technically called IMPLICIT DEFERRED LOADING) is loading data only when and if you need it. It lets you do things like reference the ingredients of a recipe even when you haven’t loaded them.

In Entity Framework, lazy loading is controlled by setting the LazyLoadingEnabled property on the context, but the property is exposed in different places depending on which API you use:

In the objectcontext API

In the dbcontext API ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required