1

I'm requiring a way to audit an MVC3 EF application capturing the following values:

  • Timestamp
  • Field Name
  • Old Value
  • New Value

I think I've wrongfully done the binding manually, and as a result all the row is updated after an edit (so trigger will assume everything is being updated)... therefore rather avoid DB triggers as it'll need a re-write of all the binding.

I would imagine, if I can capture the old values (somehow), and then compare to the new values, I can populate an audit table with the above fields.

Any advice on this would be much appreciated.

stats101
  • 1,727
  • 7
  • 30
  • 49

2 Answers2

1

Depending on the version of SQL you using you could look in to Change Data Capture

TWith2Sugars
  • 3,356
  • 2
  • 25
  • 43
0

You can subscribe to the saving changes event of the entity. Here is an example... Change History in MVC and EF

Community
  • 1
  • 1
Ryand.Johnson
  • 1,884
  • 2
  • 16
  • 21
  • This works well for scalar properties but doesn't cover relationships. If you are using foreign key associations (i.e. have fields for foreign keys in your entities) you will see IDs change, but many-to-many relationships will not be covered. – LeffeBrune May 24 '12 at 17:55