Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Session.Evict()

Tags:

c#

nhibernate

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?

like image 431
lomaxx Avatar asked Mar 24 '09 22:03

lomaxx


2 Answers

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.

like image 195
Danielg Avatar answered Nov 04 '22 04:11

Danielg


You will receive a NHibernate.LazyInitializationException.

like image 6
Luke Avatar answered Nov 04 '22 04:11

Luke