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:



One Reply to “Entity Framework: eager and lazy loading”

Leave a Reply

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

Solve : *
21 + 6 =