Auditing - retrieving primary key

Posts   
 
    
Elt
User
Posts: 2
Joined: 31-Oct-2007
# Posted on: 31-Oct-2007 05:09:35   

Hi there,

I am implementing the new auditing framework, using the sample in the documentation as a starting point.

I don't have much experience with implementing auditing. I'm assuming that the ability to identify the row in the database that has been inserted/deleted/updated is a common requirement, but I'm a bit confused as to how to achieve it!

All my tables have a field called ID which I could include in my audit data, but if I try to reference it from within any of the audit events I receive an entity out-of-sync exception. I guess that would be null for a new record anyway, since their primary keys are Identity fields.

Any guidance appreciated.

Thanks, Andrew

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-Oct-2007 08:47:05   

The entity being audited is passed to the Audit events/handlers. You will have to cast it to the specified entity type to access its fields, as follows:

    public override void AuditUpdateOfExistingEntity(IEntityCore entity)
    {
        int customeID  = ((CustomerEntity)entity).CustomerId;
    }
Elt
User
Posts: 2
Joined: 31-Oct-2007
# Posted on: 01-Nov-2007 04:25:29   

Thanks! I thought I tried that and received OutOfSync exceptions, but I must I must have been doing something wrong because it works fine now.

Cheers, Andrew