Sergey Metlov
Sergey Metlov

Reputation: 26341

NHibernate lazy loading. Retrieve data on demand

I have some class with associated list. I want this list not to be loaded when I retrieve the entity, but I want to have an opportunity to load this list later, outside the session in which I cought the entity. Can NHibernate's lazy mechanism do this? Thanks!

Upvotes: 0

Views: 550

Answers (2)

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99750

In theory you can implement your own IBytecodeProvider / ProxyFactory and do whatever you want. But that's quite complex, so you'll want to stick to regular NHibernate usage, which dictates that lazy loading requires an active session. It can be the originating session or you can reattach an entity from a previous session using ISession.Lock()

Upvotes: 1

aaaa bbbb
aaaa bbbb

Reputation: 3043

From outside of the session, you will always get an exception when you access an not-yet loaded object.

There is a way to get your objects from a new session. What you want to do is known as "Remote Lazy Loading". See http://www.theserverside.com/news/1363571/Remote-Lazy-Loading-in-Hibernate

Upvotes: 0

Related Questions