Entity auditing in CastleActiveRecord

In my Castle ActiveRecord based application I have a base class named ARSuperClass that all my domain entities except than EntityLogger inherit from it instead of inheriting from ActiveRecordBase. I have ModifyDate and CreateDate fields in ARSuperClass that must be updated each time an entity is created or updated. Additionally each creation/updating operations must be logged in EntityLogger too.

In first solution I overrode OnSave and OnUpdate then changed ModifyDate and CreateDate in them and also added a new record to EntityLogger. This solution was working but with each entity update, two updates were occurring. It was because with changing audit fields, the object went dirty again and so another update was needed.

In second solution I replaced OnSave with BeforeSave and replace OnUpdate with OnFlushDirty. This solved duplicate updates with entity creation but entity updates were still generating two updates.

In third solution I searched for something like BeforeUpdate but Castle ActiveRecord didn’t have such a thing. So I used NHibernate’s IPreUpdateEventListener and all my problems get solved.

For more info about how to use NHibernate event listener in Castle ActiveRecord go here.

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *