Implementing the Linqtosql DataContext Elementary Class - How to Check Before / After Values

I am trying to extend the linqtosql classes generated by the VS constructor and need to determine if the value of a specific field has changed. Is there a way to access before and after values ​​for a field in the DataContext update method for a table / object?

Here is 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 am also open to adding a property to the Activity entity class to let me know if a value has changed, but I can't figure out how to determine if a value has changed there. I can't just use the OnAssignedToChanged method of the Activity class because it fires whenever a property value is set, optionally changed. I am using the ListView control and LINQDataSource to update, so it is installed no matter what.

, OnAssignedToChanging, Activity, , . this.AssignedTo null.

partial void OnAssignedToChanging(int? value)
{
   if (value != this.AssignedTo)
   {
      _reassigned = true;
   }
}
+3
1

:

public partial class DataClassesDataContext
{
    partial void UpdateActivity(Activity instance)
    {
        Activity originalActivity = Activities.GetOriginalEntityState(instance);
        if (instance.Property != originalActivity.Property)
        {
            // Do stuff
        }
        this.ExecuteDynamicUpdate(instance);
        //need to compare before and after values to determine if instance.AssignedTo value has changed and take action if it has
    }
}

:

public partial class DataClassesDataContext
{
    partial void UpdateActivity(Activity instance)
    {
        ModifiedMemberInfo[] changes = Activities.GetModifiedMembers(instance);
        foreach (var change in changes)
        {
            Console.WriteLine("Member: {0}, Orig: {1}, New: {2}", change.Member, change.OriginalValue, change.CurrentValue);
        }

        this.ExecuteDynamicUpdate(instance);
        //need to compare before and after values to determine if instance.AssignedTo value has changed and take action if it has
    }
}

(OnAssignedToChanging(int? value)), , , . , ? , , , .

+9

All Articles