Maintain Table History with Nhibernate

254 Views Asked by At

I have a situation where I have to maintain History of a table.

For Eg: I have PaymentTransaction Table and I want to keep PaymentTransactionHistory for auditing purposes.

Do we have anything in NHIbernate that can be used to achieve this. I read about IInterceptor and Events and couldn't really understand if they could be of any use in my case.

I am using Fluent NHIbernate.

Many Thanks

2

There are 2 best solutions below

0
Doan Van Tuan On

In my project this is done by an interceptor, using following methods:

  • When something got deleted, process it in OnDelete
  • When something inserted into DB, process it in OnSave
  • When something changes, process it in OnFlushDirty
  • There are some other methods for handling collection.

Just try them, it's not difficult.

1
DanP On

NHibernate Envers may also be an option for you - but possibly an overkill for the usage you mentioned.