Write an insert or update and auditing Entity changes?How can I do it? -


when insert/updating entity need log properties have changed. lets take 2 tables customer , address. customer can have many addresses.

task:

write audit table properties have changed?

what way write update method if that.

i have seen can use following:

  objectstateentry entry = objectstatemanager.getobjectstateentry(entity);   var changes=  entry.getmodifiedproperties(). 

not sure how write method though following half attempt: can give me few pointers or me code?

  private  bool updatecustomer(customer modifiedcustomerdto)   {      using (var ctx = new mycontext())      {         var oldcustomer = ctx.customers.where(xx => xx.customerid == modifiedcustomerdto.id).single();         oldcustomer.name = modifiedcustomerdto.name;         oldcustomer.surname = modifiedcustomerdto.surname;          foreach (var oldaddress in oldcustomer.addresses)         {           //if it's new address add             //else updateit            //write audit table properties have changed.         }          //get modified properties , write auditlog          ctx.savechanges();      }   } 

take @ this post dealing savingchanges event.
can check properties of object being updated in event , log them using custom code.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -