Entity Framework: eager and lazy loading

  • lazy loading:
    • delaying load of data until we specifically request for it
    • i.e. accessing customer.Address loads Address of a customer in the background via separate SQL query
    • property needs to be public, virtual
    • context.Configuration.ProxyCreationEnabled should be true
    • context.Configuration.LazyLoadingEnabled should be true
    • to disable lazy loading completely Context.Configuration.LazyLoadingEnabled = false;
  • eager loading
    • opposite of lazy loading
    • loads related entities as part of the query
    • done via .Include() query

Further read:

https://www.entityframeworktutorial.net/lazyloading-in-entity-framework.aspx

https://www.entityframeworktutorial.net/eager-loading-in-entity-framework.aspx

Leave a Reply

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

Solve : *
20 + 11 =