开发者

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

开发者 https://www.devze.com 2022-12-16 07:52 出处:网络
Is there a scenario where eager loading is preferred ove开发者_高级运维r lazy loading?You may require a fully populated object graph before passing it to another layer i.e. when working with what NHib

Is there a scenario where eager loading is preferred ove开发者_高级运维r lazy loading?


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.


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消