tags:

views:

288

answers:

1

If I set dynamic-update=true I've found that fields updated in my Interceptor do not get included in the update statement that goes to the database. When I set it to false all the columns including the time stamp get updated. I really want to use dynamic update.

public class Interceptor : EmptyInterceptor
{
  public override Boolean OnFlushDirty(object entity, object id, object[] state,
    object[] previousState, string[] propertyNames, IType[] types)
  {
    var auditEntity = entity as BaseAuditEntity;

    if (auditEntity != null)
    {
      var now = DateTime.Now;
      var index = Array.IndexOf(propertyNames, "LastModifiedTimestamp");
      state[index] = now;
      auditEntity.LastModifiedTimestamp = now;
    }
    return base.OnFlushDirty(entity, id, state, previousState, propertyNames, types);
  }

}

I thought that this line would have marked my the last modified column as dirty.

auditEntity.LastModifiedTimestamp = now;

Is there something I should do in my interceptor to mark the time stamp field as dirty?

+2  A: 

The API-Doc says: "returns true if the user modified the currentState in any way."

Did you try to return true instead of calling the empty base implementation?

public class Interceptor : EmptyInterceptor
{
  public override Boolean OnFlushDirty(object entity, object id, object[] state,
    object[] previousState, string[] propertyNames, IType[] types)
  {
    var auditEntity = entity as BaseAuditEntity;

    if (auditEntity != null)
    {
      var now = DateTime.Now;
      var index = Array.IndexOf(propertyNames, "LastModifiedTimestamp");
      state[index] = now;
      auditEntity.LastModifiedTimestamp = now;

      return true;
    }
    return base.OnFlushDirty(entity, id, state, previousState, propertyNames, types);
  }

}
zoidbeck
That worked. Thanks! I thought I already tried that, but I've been trying a lot of different stuff lately.
Jerry