Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I detach an object from an NHibernate session?

If I've gotten a persistent object from the database via NHibernate's Get() or Load() methods, is there a way for me to detach that object from its NHibernate session so that changes to it will not automatically be persisted?

like image 586
Brian Sullivan Avatar asked Jun 29 '09 16:06

Brian Sullivan


People also ask

What is NHibernate session?

The NHibernate session encapsulates a unit of work as specified by the unit of work pattern.

What does NHibernate flush do?

An nHibernate session maintains all changes to the object model. At some point, it needs to synchronize these changes with the database.


1 Answers

Try Session's Evict method.

Changes to the instance will not be synchronized with the database. This operation cascades to associated instances if the association is mapped with cascade="all" or cascade="all-delete-orphan".

like image 73
wtaniguchi Avatar answered Nov 16 '22 03:11

wtaniguchi