tags:

views:

2593

answers:

3

I don't have access to code here in front of me so I was just wondering if someone could help me out with Session.Evict().

Say I have a Person object with a child collection of Addresses. I populate the Person object from a session and lazy load the Addresses collection. I then call Session.Evict(personObject) to detach the Person object from the session. My question is, if I attempt to access the Addresses collection will it just return null, or will I get an exception because the NHibernate proxy can't find the associated session?

A: 

I also don't have code in front of me, but from memory, you'll probably get an exception.

If you have lazy loading on and working, NHibernate will try to load the Addresses collection. It should never return an incorrect value/collection, it'll only complain when it can't load what's been asked.

Damovisa
this makes sense... when I get a chance I'll test it out. Thanks for the answer
lomaxx
+3  A: 

If you cause the lazy load to happen before you evict the entity, then the collection will be accessible even after the eviction. However if you evict the entity and then try to lazy load the child collection you will get an exception.

Danielg
+3  A: 

You will receive a NHibernate.LazyInitializationException.

Luke