0

(sorry for my bad english)

Hey, I need to log all changes that happens on my database for auditing purposes. When I insert or delete a entity, it is easy but when I update something, I need to save what properties have changed and from/to what values. My domain service is a DbDomainService. How can I get the changes? Do I need to hit the database to see the old values and compare it myself?

Leo
  • 7,061
  • 6
  • 26
  • 43
  • possible duplicate of [Implementing Audit Log / Change History with MVC & Entity Framework](http://stackoverflow.com/questions/6867459/implementing-audit-log-change-history-with-mvc-entity-framework) – Eranga Feb 27 '12 at 10:51

1 Answers1

0

There is more elegant means of doing this (e.g. Using Aspect coding techniques), but I had one isolated case in which I did this. This is the standard update for WCF RIA Services, on the server side, for each entity that you allow updates to occur.

public void UpdatePackingSlip(PackingSlip currentPackingSlip)
{

  var BeforeUpdate_PackingSlip = this.ChangeSet.GetOriginal(currentPackingSlip);
  //at this point you can compare the original values from the updated values, and capture
  // whatever you want todo

Just make sure you don't change the code that attaches the object back to the object context.

codeputer
  • 1,854
  • 2
  • 18
  • 43
  • codputer, that was my first guess but `this.ChangeSet.GetOriginal(currentEntity)` always return null. I do not know if is a RIA thing... looking through fiddler, I can see that only the changed values (and not the originals)is being send to server on SubmitChanges. – Leo Feb 28 '12 at 18:43