How to determine which fields have changed?

Posts   
 
    
Posts: 48
Joined: 14-Oct-2008
# Posted on: 07-Nov-2008 15:15:09   

Is there an easy way to do this without resorting to capturing PropertyChanged event or other similar event handling? I simply want to be able to look at an object and iterate thru the fields to determine which ones of them have changed, and be able to at least determine the field name, but ideally also the new value and if possible without another DB call, the original value.

-mdb

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Nov-2008 18:50:45   

Hi mdb, here is an code example of how you can achieve that (assuming Adapter TemplateSet):

foreach (EntityField2 field in myEntity.Fields)
{
    if (field.IsChanged)
    {
        Console.WriteLine("field name: {0}", field.Name);
        Console.WriteLine("original value: {0}", field.DbValue);
        Console.WriteLine("current value: {0}", field.CurrentValue);
    }
}
David Elizondo | LLBLGen Support Team