I'm trying to extend the linqtosql classes generated by the VS designer and need to determine if the value of a specific field has changed. Is there a way for me to access the before and after values for a field in the DataContext Update method for a table/entity?
Here's my code:
public partial class DataClassesDataContext
{
partial void UpdateActivity(Activity instance)
{
this.ExecuteDynamicUpdate(instance);
//need to compare before and after values to determine if instance.AssignedTo value has changed and take action if it has
}
}
I'm also open to adding a property to the Activity entity class to signal whether the value has changed but I can't figure out how to tell if the value has changed there either. I can't just use the OnAssignedToChanged method of the Activity class because it fires whenever the property value is set, not necessarily changed. I'm using the ListView and LINQDataSource control for updating so it gets set no matter what.
I also thought I might be able to use the OnAssignedToChanging method but the Activity instance does not seem to have current values at that point. The following code does not work as this.AssignedTo is always null.
partial void OnAssignedToChanging(int? value)
{
if (value != this.AssignedTo)
{
_reassigned = true;
}
}