Auditing changed fields

Posts   
 
    
HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 26-Oct-2005 22:46:54   

Hi,

a simple question simple_smile

Is there an easy way to get a collection of changed fields ? So when an entity reports "IsDirty", I would like to know which fields are dirty without having to iterate over all fields (and subsequently recursing over all subobjects fields).

thnx in advance !

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 28-Oct-2005 02:54:51   

The only thing that I can think of to get away from this would be to add the changed entities to another collection when they are changed. Could you give an example of what you are trying to do and we may be able to give you a better answer.

omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 28-Oct-2005 09:27:53   

bclubb wrote:

The only thing that I can think of to get away from this would be to add the changed entities to another collection when they are changed. Could you give an example of what you are trying to do and we may be able to give you a better answer.

Is there a single event that is fired when any field changes or do I have to this in each fields OnxxChanged() event ??

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 28-Oct-2005 11:17:32   

omar wrote:

bclubb wrote:

The only thing that I can think of to get away from this would be to add the changed entities to another collection when they are changed. Could you give an example of what you are trying to do and we may be able to give you a better answer.

Is there a single event that is fired when any field changes or do I have to this in each fields OnxxChanged() event ??

yes : EntityContentsChanged

Frans Bouma | Lead developer LLBLGen Pro
HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 29-Oct-2005 03:52:32   

Could you give an example of what you are trying to do and we may be able to give you a better answer.

Sure i can simple_smile

I have an entity with a lot of fields, and a GUI winform with databound controls. When a user saves the entity, behind his back there is some info written into an auditing table by an auditor object. The info consist of a userID, entityID, actionID (action = create/update...) and a description field. In the description text i want to provide text like "fields updated : " and then the changed fieldnames. One way to do this is to iterate over all fields of the entity, compare their currentValue to the DBValue, and if it's changed add it to the description. Now i just wanted to know if llblgen allready provides a mechanism for this, eg. a collection with the changed fields.

But coming to think of it, my first method is probably the simplest, at least simpler then dragging along a collection with "changed fields" all the way to the "auditor"...

Anyways thanx for the suggestions simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 30-Oct-2005 14:02:18   

HcD wrote:

Could you give an example of what you are trying to do and we may be able to give you a better answer.

Sure i can simple_smile

I have an entity with a lot of fields, and a GUI winform with databound controls. When a user saves the entity, behind his back there is some info written into an auditing table by an auditor object. The info consist of a userID, entityID, actionID (action = create/update...) and a description field. In the description text i want to provide text like "fields updated : " and then the changed fieldnames. One way to do this is to iterate over all fields of the entity, compare their currentValue to the DBValue, and if it's changed add it to the description. Now i just wanted to know if llblgen allready provides a mechanism for this, eg. a collection with the changed fields.

No, because these aren't tracked in a separate collection simple_smile . When a field gets changed, it fires an event which is bubbled upwards to the entity, which fires its EntityContentsChanged event. The event is used to set flags, not keep track of which fields are changed.

Frans Bouma | Lead developer LLBLGen Pro