How to log update changes use Auditing?

Posts   
 
    
xc_lw2000
User
Posts: 48
Joined: 12-Dec-2006
# Posted on: 17-Jan-2009 01:42:39   
 I'm using an Auditor to log user's changes.
 I create a auditor inherited from AuditorBase,and override the method OnAuditUpdateOfExistingEntity,in this method I iterate the fields,and store DbValue and CurrentValue of every field be changed. But I find that both the two value is equal and is the value be saved successfully.

for example

MyEntity entity =new MyEntity(pkValue); adapter.FetchEntitty(entity); string temp=entity.Field1;//Now the field's value is "AAA"; entity.Field1="BBB"; adapter.SaveEnttiy(entity);

in my Auditor

public override OnAuditUpdateOfExistingEntity(IEntityCore entity) { foreach(IEntityField2 field in entity.Fields) { if(field.Name=="Field1") { string originalValue=field.DbValue;//"BBB"????Not "AAA" string newValue=field.CurrentValue;//"BBB"

        }
  }

}

It seems that in OnAuditUpdateOfExistingEntity,the entity already be saved successfully.How can I get the original value and then I can log the detail changes of this entity?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Jan-2009 04:09:16   

Your are right, that method is called just after the entity has been saved. You should override the OnAuditEntityFieldSet(int fieldIndex, object originalValue) AuditEntityFieldSet method. You could save the changes in an array and persist them on the OnAuditUpdateOfExistingEntity method.

Similar thread: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=10913 Also, check the Auditing example at http://llblgen.com/pages/examples.aspx .

David Elizondo | LLBLGen Support Team