NHibernate为什么需要不可设置的成员进行虚拟化? [英] Why does NHibernate need non-settable members to be virtual?
问题描述
NHibernate不仅要求域的可设置属性是虚拟的,而且还要求仅获取属性和方法.有人知道原因是什么吗?
NHibernate requires not only settable properties of your domain to be virtual but also get-only properties and methods. Does anyone know what the reason for this is?
我无法想象可能的用途.
I cannot imagine a possible use.
推荐答案
原因是延迟加载.为了使延迟加载成为可能,创建了一个代理类.它必须必须拦截外部"的每个调用,以便在执行实际的方法/属性之前加载您的实体.如果某些方法/属性不是虚拟的,则将无法拦截这些调用,并且不会加载实体.
The reason is lazy loading. In order to make lazy loading possible, a proxy class is created. It must intercept every call from "outside" in order to load your entity before actual method/property is executed. If some methods/properties were not virtual it would be impossible to intercept these calls and entity wouldn't be loaded.
这篇关于NHibernate为什么需要不可设置的成员进行虚拟化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!