1

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 fetch Person object
  • 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!

4

1 回答 1

1

但是我不知道如何从 OldState 数组创建一个 Person 对象并保存它。

你看过NHibernate Envers吗?它就是这样做的。

如果您出于某种原因不想使用此框架,请查看其源代码。

于 2012-09-05T17:21:43.860 回答