Entity Framework – deferred loading, deferred loading and Eagle loading in Entity Framework
What is the difference between these three types of loading? Can anyone explain an example? Different online resources use different definitions, resulting in more confusion than necessary
Solution
Delay loading and delay are synonymous (AFAIK, please correct me if I am wrong) There is a big difference between eager and lazy Desire will happen earlier, lazy will only happen "on demand" and execution will happen at the DB level – let's take a simple join statement as an example
var people = (from p in people SELECT p).ToList(); var jobs = (from j in jobs SELECT j).ToList(); var peopleAndJobs = (from p in people JOIN j on j.personId equals p.personId SELECT p).ToList()
This is an example of eager loading We get all the people, all the work, and we're adding memory Not very clever (usually) This is the lazy style
var people = (from p in people SELECT p); var jobs = (from j in jobs SELECT j); var peopleAndJobs = (from p in people JOIN j on j.personId equals p.personId SELECT p).ToList()
This creates an iqueryable for people and work (iqueryable is lazy), and the connection occurs in the database This saves network activity and is usually actually faster because the DB has been optimized for connectivity, etc
Unless we explicitly say, "I need that data!" (through tolisting, iteration, etc.) it is lazy There are some more quirks, but this should be a good introduction