Reputation: 17773
I'm taking advantage of great article:
http://ayende.com/blog/3987/nhibernate-ipreupdateeventlistener-ipreinserteventlistener
and have implemented OnPreInsert exactly like in the example. However, my auditing requirement when updating the entity, is to create a "history" entry in database. Let's say:
I modify
personObj.FirstName = Console.ReadLine();
then I save the entity. Now, in IPreUpdateEventListener.OnPreUpdate I want to change UpdatedAt & UpdatedBy properties of Entity & State (just like in the article), and also I need to add a new record to database that contains old values (FirstName before change).
I saw that PreUpdateEvent contains OldState array, however I have no idea how to create a Person object fron OldState array and save it.
How can I achieve what I need?
Thanks!
Upvotes: 1
Views: 1172
Reputation: 1950
however I have no idea how to create a Person object fron OldState array and save it.
Have you had a look at NHibernate Envers? It does just that.
If you don't want to use this framework for some reason, take a look at its source code.
Upvotes: 1