Firstly, this is not something you should do. NHibernate tries it very best to do stuff like dirty checking correct. If NHibernate thinks it's dirty, it probably is. Try to find out what changes you've made to the entity which cause NHibernate to think it's dirty and see whether you can solve your issue by tuning this.
That said, there is a solution. NHibernate uses listeners that fire before insert and update. More information on this can be found at http://ayende.com/Blog/archive/2009/04/29/nhibernate-ipreupdateeventlistener-amp-ipreinserteventlistener.aspx, http://www.codinginstinct.com/2008/04/nhibernate-20-events-and-listeners.html and many other locations.
The event listeners themselves have a return value. What this return value does is tell NHibernate whether to execute the actual insert/update SQL queries. When you return false
, it executes them. When you return true
, it does not. This way you can suppress the actual persistence to the database.
The nice thing of this approach is that where NHibernate is concerned, it believes that the entities actually were persisted, so the internal state of NHibernate stays correct and the entities become not-dirty.