NHibernate lazy loading property - what does build-time bytecode instrumentation mean?

◇◆丶佛笑我妖孽 提交于 2019-12-13 17:59:19

问题


I've tried to lazy-load a property in my domain model, but lazy loading doesn't work. (It is always loaded).

[Property(0, Column = "picture", Lazy=true)]
public virtual System.Byte[] Picture
{
       get { return picture; }
       set { picture = value; }
}

When reading the documentation here it says that it requires build-time bytecode instrumentation. What does this mean - and how can I get it ?


回答1:


I have you tried a collection rather then an array?

[Property(0, Column = "picture", Lazy=true)]
public virtual IList<System.Byte> Picture
{
       get { return picture; }
       set { picture = value; }
}



回答2:


For lazy loading to work NHibernate makes use of interception (via dynamic objects). That means it wraps your call to Picture and when you first call Picture it it will load the property from the database.

For this to work it can use one of three types of Dynamic object frameworks:

  • Castle DynamicProxy
  • Linfu
  • Spring

When you download NHibernate there is another folder with three types of these dynamic object plugins and you need to copy three dlls to the nhibernate folder (where nhibernate.dll is) and set a property in your nhibernate configuration file.

<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>

Ref: http://nhforge.org/blogs/nhibernate/archive/2008/11/09/nh2-1-0-bytecode-providers.aspx

HTH Alex



来源:https://stackoverflow.com/questions/1497179/nhibernate-lazy-loading-property-what-does-build-time-bytecode-instrumentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!