AuditEntityFieldSet only called when assigning different value

Posts   
 
    
Aeon
User
Posts: 24
Joined: 21-Jul-2008
# Posted on: 09-Apr-2009 21:13:45   

Because AuditUpdateOfExistingEntity is called after a save occurs, I need to set values / do work as entity properties are assigned.

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=13413&HighLight=1 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=11145&HighLight=1

It appears that the AuditEntityFieldSet overload is only called when assigning a value that is different from the original. My auditor hits the db to run a stored proc when an amount field changes in order store a difference between what was typed in and what was returned by the sproc.

1) Is there any chance of making AuditUpdateOfExistingEntity occur prior to the save (so that field.dbValue would be the original value, for instance)?

2) Is there any way to force setValue to call auditEntityFieldSet (other than calling it from the UI)

Thanks, -Ian

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 10-Apr-2009 10:10:07   

It appears that the AuditEntityFieldSet overload is only called when assigning a value that is different from the original. My auditor hits the db to run a stored proc when an amount field changes in order store a difference between what was typed in and what was returned by the sproc.

Would you please explain what's the problem in the above logic?

Aeon
User
Posts: 24
Joined: 21-Jul-2008
# Posted on: 10-Apr-2009 16:52:01   

Not much. In my case, the sproc uses many fields, and takes in a primary key (so it needs to be aware of existing data, prior to changes), so currently I am forced to hit the db whenever any field changes.

From a design perspective, one could argue that since there are dbValue and currentValue, that it could be left up to the overLoad to decide to do work if they are different.

Honestly, I think this illustrates a bad choice of mine (because of the assumption that I'd have access to previous values) to use the auditor in this case.

If I had to do it over, I might tie into the adapter's onBeforeEntitySave, and call a function on the auditor, or do all the work in the adapter.

Thanks.

Aeon
User
Posts: 24
Joined: 21-Jul-2008
# Posted on: 10-Apr-2009 20:19:49   

Ok.. new approach. I added an event to the entityClass on before save that I am handling in the auditor.

But EntityBase2.OnBeforeEntitySave doesn't seem to be called upon inserts. If this is the case, shouldn't there be OnBeforeEntityUpdate and OnBeforeEntityInsert?

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 13-Apr-2009 10:57:51   

Please use the DataAccessAdapter's OnBeforeEntitySave()

protected virtual void OnBeforeEntitySave( 
   IEntity2 entitySaved,
   bool insertAction
)