What are the differences between these 3 types of loading? Can someone explain with an example? Different resources online use different definitions causing more confusion than necessary.
What are the differences between these 3 types of loading? Can someone explain with
Share
Lazy loading and Deferred are pretty synonymous (AFAIK, please correct me if I’m wrong). The big difference is between Eager and Lazy. Eager will happen up front, Lazy happens only “as needed” and execution will happen at the DB level- let’s take a simple JOIN statement as an example
This is an example of eager loading. We are getting ALL people, ALL jobs, and we are doing the join in memory. Not very smart (usually). Here is what it looks like Lazy-style.
What this is doing is creating an IQueryable for both people and job (IQueryable is lazy), and the join is happening in the DB. This saves network activity, and is usually actually faster, since the DB is optimized to do joins and such.
Unless we explicitly say “I need that data!” (by ToListing it, iterating through it, etc) it’s lazy. There are some more quirks but this should be a decent primer.