在EF CodeFirst中记录用户更改的历史记录 [英] Logging history of user changes in EF CodeFirst

查看:92
本文介绍了在EF CodeFirst中记录用户更改的历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在DB记录上保存用户更改的历史记录。编辑记录(例如,名称字段的值由yyyy / dd / mm中的用户1从n更改为x),删除记录和...。




请建议在EF codefirst中实现此方法。



编辑后:

哪一个更好?

1.创建一个表来保存所有表日志

2.为数据库中的每个表创建一个表

解决方案

覆盖SaveChanges方法



在SaveChanges方法中循环使用ObjectStateManager.GetObjectStateEntries



然后使用ObjectStateEntry CurrentValues.DataRecordInfo.FieldMetadata []。FieldType.Name和entry.CurrentValues来获取名称值对


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

解决方案

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

这篇关于在EF CodeFirst中记录用户更改的历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆