Search code examples
nhibernatefluent-nhibernatenhibernate-3

State change instead of real delete


Is it possible to overload Session.Delete() behavior to not to perform real deleting from DB but update value of int State column to special deleted value? And would be great to restrict then loading of deleted entities by GetAll() method.


Solution

  • This kind of a Delete is called Soft Delete. You can use interceptor to override Session.Delete() and use where on class mapping to define a formula, like:

    <class where="State=0" ...>
    

    Gabriel Schenker has an example on nhforge.org: http://nhibernate.info/blog/2008/09/06/soft-deletes.html