Question

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.

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top