Auditor Class - Missing Fields

Posts   
 
    
Posts: 26
Joined: 29-Sep-2011
# Posted on: 18-Oct-2018 23:53:10   

We use auditor classes to capture data into our history tables anytime an entity is saved. In the entity class, we inject an auditor class with this override

protected override IAuditor CreateAuditor()
{
    return new UiClaimAuditor();
}

Anytime an entity is updated, the following base method is called in GenericAuditor class (attached)

public override void AuditUpdateOfExistingEntity(IEntityCore entity)
{
    base.AuditUpdateOfExistingEntity(entity);
}
public override void AuditDirectUpdateOfEntities(IEntityCore entity, IPredicate filter, IRelationCollection relations, int numberOfEntitiesUpdated)
{
    base.AuditDirectUpdateOfEntities(entity, filter, relations, numberOfEntitiesUpdated);           
}

After the recent upgrade to v5.3, the entity that is passed to the AuditDirectUpdateOfEntities is missing entity field values. For example

In the below code. When the UpdateMulti is called, the entity passed to the base auditor method(AuditDirectUpdateOfEntities) is missing values

UiClaimCollection coll = new UiClaimCollection();
PredicateExpression filter = new PredicateExpression();
filter.Add(UiClaimFields.AcctId == 13456);
filter.Add(UiClaimFields.ClaimId == 123);
UiClaimEntity entity = new UiClaimEntity();
entity.RetToWorkDt = DateTime.Now;
coll.UpdateMulti(entity, filter);

whereas, if we call the save directly on the entity, all the values are present in the entity (method - AuditUpdateOfExistingEntity).

//This works fine.  
UiClaimEntity entity = new UiClaimEntity(13456, 123);
entity.RetToWorkDt = DateTime.Now;
entity.Save();

We noticed this behavior after we upgrade to v5.3. It was working fine in v4.2.

Attachments
Filename File size Added on Approval
AuditorBase.cs 4,602 18-Oct-2018 23:53.45 Approved
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Oct-2018 07:57:47   

Hi Sunil,

This sounds pretty normal: when you use UpdateMulti (and thus yourAuditor.AuditDirectUpdateOfEntities is triggered) the available fields values are those those that you set before, in this case...

UiClaimEntity entity = new UiClaimEntity();
entity.RetToWorkDt = DateTime.Now;
coll.UpdateMulti(entity, filter);

... RetToWorkDt is the only field you really set. The AuditDirectUpdateOfEntities could be used to audit the action of general update of RetToworkDt field for those entities that fit the criteria.

I doubt that this worked differently in v4.2. So maybe it is something different that changed in your code. What happen if you back to your old code using v4.2? Are you sure that this worked differently?

David Elizondo | LLBLGen Support Team
Posts: 26
Joined: 29-Sep-2011
# Posted on: 26-Oct-2018 22:33:09   

You were right. We had an override method in a partial class checking for null which I was missing after the upgrade.