30 April 2024

Eager Loading, Lazy Loading

Eager Loading, Lazy Loading

Eager Loading helps you to load all your needed entities at once; i.e., all your child entities will be loaded at single database call. This can be achieved, using the Include method, which returs the related entities as a part of the query and a large amount of data is loaded at once.

User usr = dbContext.Users.Include(=> a.UserDetails).FirstOrDefault(=> a.UserId == userId);

Lazy Loading
It is the default behavior of an Entity Framework, where a child entity is loaded only when it is accessed for the first time. It simply delays the loading of the related data, until you ask for it.

User usr = dbContext.Users.FirstOrDefault(=> a.UserId == userId);

No comments:

Post a Comment

Comments Welcome

Benefits of microservices

Benefits of microservices      1. Development & Team Agility Architecture- and language-neutral: Teams aren't locked into one progr...