Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine which fields where changed in a Linq-To-Sql Object

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

like image 599
Carlos G. Avatar asked Sep 04 '09 10:09

Carlos G.


1 Answers

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);
like image 70
BlueMonkMN Avatar answered Sep 18 '22 17:09

BlueMonkMN