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

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

问题描述

只是阅读有关NHibernate的,为什么类的属性必须是虚拟的?什么是背后的reasononing?

Just reading about nHibernate, why do the class properties have to be virtual? What is the reasononing behind that?

推荐答案

我建议你读的一切都必须是虚与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必须是透明的懒惰   载入中。如果您检索对象   通过一个ORM,你不希望它   在整个对象自动拉   图形(默认情况下是这样),但你   不想弄乱你的code与   如果一些机构会检查   已经被加载,然后装载   如果有必要他们。这是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天全站免登陆