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 ...

Get Fluent Entity Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.