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.
Asked
Active
Viewed 88 times
0

Sergey Metlov
- 25,747
- 28
- 93
- 153
1 Answers
3
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

Owen Pauling
- 11,349
- 20
- 53
- 64

Miroslav Popovic
- 12,100
- 2
- 35
- 47
-
Hi Miroslav, I have registred Listener and it fires (as post on Gabriel Schenker blog)...but record it's not updated...can you help me? – Luigi Saggese Sep 06 '12 at 08:11
-
@Luigi You should ask this in a new question with a sample of your code. It could be hard to determine what could go wrong without the actual code. – Miroslav Popovic Sep 06 '12 at 08:45
-
http://stackoverflow.com/questions/12296076/soft-delete-nhibernate#comment16495884_12296076 – Luigi Saggese Sep 06 '12 at 10:05