问题
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