Determine if any fields have changed in an Entity (v1)

Posts   
 
    
Posts: 116
Joined: 18-Feb-2006
# Posted on: 22-Jul-2006 06:23:02   

Is there any way to determine if an entity's fields have changed? I have one entity that has about 40 fields and I don't want to compare them all to the most recent entity (but I will if that's the only way).

Any ideas?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Jul-2006 09:55:24   

First check: entity.IsDirty if that's false, no field has been changed. If true, traverse: entity.Fields and check each EntityField object (or in adapter, every EntityField2 object)'s IsChanged property. If true, that field's changed simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 116
Joined: 18-Feb-2006
# Posted on: 22-Jul-2006 15:29:15   

Otis wrote:

and check each EntityField object's IsChanged property. If true, that field's changed

Do you have an example of how to iterate through all the fields using a For Loop?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Jul-2006 16:14:03   

Underwhelmed wrote:

Otis wrote:

and check each EntityField object's IsChanged property. If true, that field's changed

Do you have an example of how to iterate through all the fields using a For Loop?


bool hasChangedFields = false;
foreach(IEntityField field in myEntity.Fields)
{
    hasChangedFields |= field.IsChanged;
    if(hasChangedFields)
    {
        break;
    }
}

Of course, for adapter use IEntityField2

Frans Bouma | Lead developer LLBLGen Pro