What does NHibernate Session.Evict do?
Asked Answered
G

2

21

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);
}
Glairy answered 20/5, 2011 at 9:17 Comment(0)
D
24

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.

Diabetic answered 20/5, 2011 at 9:23 Comment(2)
Does Evict save any changes of the object before it removes that object from the cache?Valeta
Bochen - no, it doesn't.Subminiature
A
1

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

Alveraalverez answered 6/12, 2017 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.