views:

116

answers:

4
+3  Q: 

Lazy loading...

Is there a scenario where eager loading is preferred over lazy loading?

A: 

One that I can think of offhand is when a child class is more-often-than-not accessed every time the parent is retrieved.

Daniel Auger
A: 

Yes, when you need to use the data immediately after being fetched.

Darin Dimitrov
+1  A: 

Most "reporting" needs a lot of data so it can be summarized. Why do individual fetches when you already know you need almost everything.

Generally, "extracts" for export to a data warehouse or other system will benefit from eager loading.

S.Lott
+2  A: 

You may require a fully populated object graph before passing it to another layer i.e. when working with what NHibernate refers to as detached instances.

Lazy loading only works within the context of an ISession. With aggregates any child objects would generally be loaded with the parent but you may have some scenarios where it would be inneficient to load child objects especially when they were not required to undertake any processing you were going to do.

David