views:

94

answers:

1

I I have a linq-to-sql database in which I want to log some of the changes made to an entity. Right now, I'm getting the updated entities by reading the DataContext.GetChangeSet().Updates property, but that doesn't provide me with the fields from the entity that were changed.

Is there a way to know which fields were modified in an updated entity??

Thanks

+3  A: 

The DataTable has a method GetModifiedMembers that will return a list of members that have changed for a specified entity instance.

DataClasses1DataContext context;
Class1 instance = context.GetChangeSet().Updates.OfType<Class1>().First();
context.Class1s.GetModifiedMembers(instance);
BlueMonkMN