gpt4 book ai didi

.net - nhibernate 和虚拟类属性?

转载 作者:行者123 更新时间:2023-12-03 03:25:51 25 4
gpt4 key购买 nike

刚刚阅读了有关 nHibernate 的内容,为什么类属性必须是虚拟的?

这背后的原因是什么?

最佳答案

我建议您阅读Must Everything Be Virtual With NHibernate?

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

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.

关于.net - nhibernate 和虚拟类属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/848108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com