views:

62

answers:

2

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.

+2  A: 

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.

Jan Willem B
A: 

You might try looking at your system in different light.

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

epitka