1

I want save history of user changes on DB Records. Changes such as edit records (for example value of FirstName field changed from 'n ' to 'x' by user1 in yyyy/dd/mm") , Delete Records and ... .

please suggest a method to implement this in EF codefirst.

After Edit:
And which one is better?
1.Create one table to save all tables log
2.Create a table for each table in database

Hossein Moradinia
  • 6,116
  • 14
  • 59
  • 85

1 Answers1

2

Override the SaveChanges method.

In your SaveChanges method loop through the entries using ObjectStateManager.GetObjectStateEntries

Then use the ObjectStateEntry CurrentValues.DataRecordInfo.FieldMetadata[].FieldType.Name and the entry.CurrentValues to get the name value pairs

Kirsten
  • 15,730
  • 41
  • 179
  • 318