Is there any utility or built in class in NHibernate that force a class to load it without lazy in a special situation?

一世执手 提交于 2019-12-11 13:03:54

问题


I have an web application that uses NHibernate as ORM. I enable lazy loading for my classes but I want to load some classes without lazy in a special situation.

Now is there any utility or built in class in NHibernate that force a class to load it without lazy in a special situation?

Note: I don't want to remove lazy property in my mapping file, because I use lazy loading in some of time.


回答1:


Yes. If you are using the ICriteria Api to specify your queries, you can use SetFetchmode to specify eager loading for some of the properties on a per-query basis.

I did a blog post on wrapping the behavior in a query object, it may be useful.




回答2:


You might try looking at your system in different light.

http://www.infoq.com/presentations/Making-Roles-Explicit-Udi-Dahan



来源:https://stackoverflow.com/questions/2987697/is-there-any-utility-or-built-in-class-in-nhibernate-that-force-a-class-to-load

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