Thursday, November 3, 2022

What is Lazy Loading and eager loading in c#

 lazy loading delays the initialization of a resource, eager loading initializes or loads a resource as soon as the code is executed.




Eager Loading When you are sure that want to get multiple entities at a time, for example you have to show user, and user details at the same page, then you should go with eager loading. Eager loading makes single hit on database and load the related entities.


Lazy loading When you have to show users only at the page, and by clicking on users you need to show user details then you need to go with lazy loading. Lazy loading make multiple hits, to get load the related entities when you bind/iterate related entities.

No comments:

Post a Comment