NHibernate何时使用延迟加载? [英] NHibernate When to Use lazy loading?

查看:130
本文介绍了NHibernate何时使用延迟加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有我对延迟加载的理解是,只有在需要对象时才加载,我们应该使用它。
请说明我们必须使用哪些场景而不使用它?
在此先感谢。

解决方案

我会这么说:


延迟加载是ORM的本质。这是ORM的原理。

p>

NHibernate是懒惰的,只是住它



从这个来源小引用:

lockquote

...默认情况下,懒惰设置为 true 的一个很好的理由,虽然我确信有一些有限的场景,其中 lazy =false 是适当的选择,它是不适合你的情况下...

从我的经验:

我几乎没有比Ayende更好的解释。但是我必须确认 - 我也是这么看的。我从来没有用过懒惰的设置。如果应该加载一些东西 - 使用预测:


  • 让ORM的东西变得懒惰

  • 根据需要调整 ad hoc 查询


All I understand about lazy loading is that it loads only when the object is needed and we should use it. Please explain me which scenarios we have to use and not use it? Thanks in advance.

解决方案

I would put it this way:

Lazy loading is the essence of ORM. It is the principle of ORM. (unless we want to load complete DB in one shot)

Check this article by Ayende:

NHibernate is lazy, just live with it

small cite from that source:

...There is a good reason why lazy is set to true by default, and while I am sure that there is some limited number of scenarios where lazy="false" is the appropriate choice, it isn’t for your scenario...

From my experience:

I would hardly explain it better than that post by Ayende. But I have to confirm - I see it the same way. I never used NON lazy setting. If something should be loaded in one shot - use projections:

  • Let the ORM stuff be lazy
  • adjust the ad hoc queries as needed

这篇关于NHibernate何时使用延迟加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆