Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disconnect object from NHibernate session

In my nhibenate session I Mapping object with AutoMapper and in the afterMap action i create new instance of the object because I extract the object from the DB for properties compare. So The AutoMapper create two instances of one object with the same ID. When I try to commit the session i get error that i have to object with the same ID.

So I Want to disconnect the object that I extract after the properties compare. After that I will can commit the session

How I do that?

Thanks!

like image 486
user556882 Avatar asked Mar 06 '11 08:03

user556882


1 Answers

You can use session.Evict(persistentObject) to evict a persistent object from the session. This will remove the object from the 1st level cache, thus allowing you to flush the session.

like image 120
mookid8000 Avatar answered Oct 06 '22 16:10

mookid8000