2

I'm handling ObjectContext's SavingChanges event to timestamp entries. The requirement is that, if only ColumnA has changed, I don't timestamp the entry when it changes.

Is there a way that I can find out which columns have changed (are changing) during this event?

lance
  • 16,092
  • 19
  • 77
  • 136

1 Answers1

3

This should work for you, this will loop through any Added/Modified entries, and if there is more than 1 modified property, and it's not "ColumnA" it you can modify the timestamp:

public int SaveChanges()
{
     foreach( ObjectStateEntry entry in ObjectStateManager.GetObjectStateEntries( EntityState.Added | EntityState.Modified ) )
     {
         var properties = entry.GetModifiedProperties();

          if (!(properties.Count() == 1 && properties.First() == "ColumnA"))
          {
              //modify timestamp here
          }
     }

    return base.SaveChanges();
}
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
Mark Oreta
  • 10,346
  • 1
  • 33
  • 36
  • 1
    Correct, except that the OP asks about the SavingChanges event. The difference is minor: http://stackoverflow.com/a/11250496/861716 – Gert Arnold Aug 09 '12 at 17:56
  • Ah you're right, apologies! It will still work, just needs to be placed in the event handler as your post showed – Mark Oreta Aug 09 '12 at 17:58