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.
Yes. If you are using the ICriteria Api to specify your queries, you can use
SetFetchmodeto 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.