nhibernate auditing with events on update

后端 未结 1 458
后悔当初
后悔当初 2021-01-06 03:00

The following code works on insert but on update modifier is never set, any ideas why?

The code for pre-update is being run and correctly sets the state

相关标签:
1条回答
  • 2021-01-06 03:37

    Edit 1: This answer has been improved
    Edit 2: It appears the the real cuase of the problem is dynamic-update set to true as found here however this solution still works for me.

    The changes get saved when you update them in the OnFlushDirty function which is called earlier.

    public override bool OnFlushDirty( object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types )
    {
        bool result = false;
    
        if (entity is IAuditable) {
            var auditable = (IAuditable)entity;
    
            Set( x => auditable.Modifier, propertyNames, auditable, currentState, SecurityManager.Identity );
            //Set( x => auditable.DateModified, args.Persister, auditable, args.State, TwentyClock.Now );
    
            result = true;
        }
    
        return result;
    }
    
    0 讨论(0)
提交回复
热议问题