views:

128

answers:

1

Here is my code:

 partial void OnisApprovedChanging(bool value)
 {            
    this.dateApproved = DateTime.Now;         
 }

'dateApproved' is updated in the business logic, but this change is not being applied to the database table. I've seen some examples where DateUpdated columns are updated whenever any edit to a table is made, but I'm only interested in updating the time-stamp when this field is updated and I'm not sure of the best way to access the DataContext from this scope.

Do I need to instantiate the Data-context and update it manually?

EDIT Did some more research, and found that some blogs suggested adding business logic on update like this:

public partial class DataContext : System.Data.Linq.DataContext
{
   partial void Updateaccount(account instance)
   {
       //business logic here      
   }
}

However, I cannot determine any way to find out if particular fields have changed. Any ideas?

A: 

Found this is the way to get the original entity and do comparisons.

partial void Updateaccount(account instance)
{            
   account acctPriorToUpdate = accounts.GetOriginalEntityState(instance);
   if (instance.isApproved != acctPriorToUpdate.isApproved)
   {
       //Do Stuff
   }            
   this.ExecuteDynamicUpdate(instance);   
}
KClough