NHibernate 1.x : many-to-one not lazily loaded

匆匆过客 提交于 2019-12-11 18:30:48

问题


This is extract of my mapping file:

<class name="XXX.A"
         table="a"
         lazy="false">

     <many-to-one name="B"
                  lazy="proxy"
                  access="field.camelcase"
                  cascade="none"
                  not-null="false"
                  class="XXX.B" 
                  column="id_b"/>

 </class>

But when A is loaded by its ID, I see "left join" to fetch B. How to prevent this?

I may add that we use ISession.Get(...) and not ISession.Load(...).


回答1:


if you have <class name="XXX.B" lazy="false"> then NHibernate does not create a proxy class for it. Because of that all <many-to-one class="XXX.B" lazy="proxy|true" /> are ignored because NH can not create proxy objects.

To enable LazyLoading of B remove lazy="false" or set <class lazy="true">. If you disabled Lazy for classes because you dont want to make every method virtual you can also implement your own Proxyclass to handle the LazyLoading



来源:https://stackoverflow.com/questions/8413832/nhibernate-1-x-many-to-one-not-lazily-loaded

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