Hossein Moradinia
Hossein Moradinia

Reputation: 6244

Logging history of user changes in EF CodeFirst

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

Upvotes: 1

Views: 3595

Answers (1)

Kirsten
Kirsten

Reputation: 18170

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

Upvotes: 2

Related Questions