Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does NHibernate Session.Evict do?

What does the following code snippet do? Why the use of Evict?

private void DoEvict(customer cust)
{
    AddressRepository.Evict(cust.Address);
    cust.Address = AddressRepository.Get(cust.Address.Id);
}
like image 307
DaSmart Avatar asked May 20 '11 09:05

DaSmart


2 Answers

The evict removes that specific "Address" reference from the NHibernate first level cache.

If the first instruction in your code snippet was not executed, the second one, instead of fetching the item from the DB, would simply return it from the first level cache.

like image 78
psousa Avatar answered Oct 28 '22 13:10

psousa


Session.evict() is used to remove a particular object from Persistent state to Detached state.

like image 25
arvind nayak Avatar answered Oct 28 '22 14:10

arvind nayak