Logging history of user changes in EF CodeFirst

戏子无情 提交于 2019-12-08 04:58:52

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/11922552/logging-history-of-user-changes-in-ef-codefirst

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!