AuditDeleteOfEntity

Posts   
 
    
blarg
User
Posts: 27
Joined: 27-Nov-2007
# Posted on: 15-Oct-2008 07:56:25   

We're using an Adapter based LLBL 2.5 Final (February 4th, 200sunglasses and an Auditing implementation. This all works beautifully except when trying to audit deleted entities.

Our auditing framework has the ability to coalesce updates to sub-entities into audit records that reference their parent objects. For example, let's say we had a CustomerEntity, and a CustomerContactEntity. Customers are 1:n with customer contacts. Whenever customer contacts are modified, we want to produce an audit record that essentially shows "Modification to CustomerEntity with Id of ____ with an actual modification to CustomerContactEntity's ___ field."

We create a set of objects that define the relationships between the aggregate entities and their children and define a field on the child entity that can be queried for the parent entity's id. (We don't support hierarchies that are more than one level deep because our database structure doesn't need to.)

Then when the audit events happen, we take the Id out of the defined FK field and connect the auditing information that way. This all works well except when trying to audit deletes. This is because by the time the auditor gets ahold of the audited entity it has already been deleted from the database, and all the fields are cleared.

We want to get the value of a CustomerContactEntity's CustomerId field in the AuditDeleteOfEntity method. As the entity is deleted, we can't fetch using the Contact's Id and a join to the customer. The fields are cleared, including DbValue, so we can't examine those. Is there a way to hook the auditing framework before the entity is removed from the database? Is there a way to force it to preserve the values in the fields so that we can create our audit records as needed?

How should we solve this issue?

Thanks for your help.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Oct-2008 12:08:30   

In this particular case you may make use of ValidateEntityBeforeDelete which is called before the deletion takes place.

Otherwise you'll need to build your own version of the ORMSupportClasses..dll to modify the DataAccessAdapterBase.DeleteEntity() method to call the CallOnAuditDeleteOfEntity() method earlier (before the actual deletion).

blarg
User
Posts: 27
Joined: 27-Nov-2007
# Posted on: 16-Oct-2008 02:26:32   

Using the validator hooks works like a charm. Thanks!