nhibernate 和虚拟类属性? [英] nhibernate and virtual class properties?

查看:18
本文介绍了nhibernate 和虚拟类属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚读到nHibernate,为什么类属性必须是虚拟的?

Just reading about nHibernate, why do the class properties have to be virtual?

这背后的原因是什么?

推荐答案

我建议你阅读 NHibernate 的一切都必须是虚拟的吗?

该问题的快速答案是:因为我们需要成员是虚拟的为了做我们的懒加载魔法/巫毒.

The quick answer to that question is: because we need members to be virtual in order to do our lazy loading magic/voodoo.

答案越长越有趣尽管.一个重要的特点是任何真正的 ORM 必须是透明的 Lazy加载中.如果你检索一个对象通过 ORM,你不希望它自动拉入整个物体图(无论如何都不是默认的),但是你不想乱扔你的代码检查是否有某些关联已经加载了,然后加载如有必要,他们.这是 ORM 的责任.理想情况下,您希望能够访问属性并拥有ORM 加载必要的数据第一次访问这些属性,如果尚未检索到数据.

The longer answer is more interesting though. An important feature that any real ORM must have is transparent Lazy Loading. If you retrieve an object through an ORM, you don’t want it to automatically pull in an entire object graph (not by default anyway), yet you don’t want to litter your code with checks to see if certain associations have been loaded yet, and then loading them if necessary. This is the ORM’s responsibility. Ideally, you want to be able to access properties and have the ORM load the necessary data upon first access of those properties if the data hasn’t been retrieved yet.

这篇关于nhibernate 和虚拟类属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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