How can you enable Lazy Loading in a DbContext?

  • Apply the [LazyLoading] attribute to entities
  • Invoke the EnableLazyLoading() method on the DbContext instance
  • Set LazyLoadingEnabled property to true in DbContext configuration
  • Use the virtual keyword for navigation properties
Lazy loading in Entity Framework allows related entities to be loaded automatically from the database when they are accessed for the first time. To enable lazy loading in a DbContext, you need to set the LazyLoadingEnabled property to true in the DbContext configuration. This allows navigation properties to be loaded lazily, meaning they are retrieved from the database only when accessed.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *