NHibernate如实体框架6+的审核日志 [英] NHibernate Envers like Audit Log with Entity Framework 6+

查看:285
本文介绍了NHibernate如实体框架6+的审核日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NHibernate Envers在实体被更新/删除时,可以很好地创建审核日志。基本上它为每个可审计实体创建一个审计表,并将数据的快照写入审计表。例如如果客户记录保存在CUSTOMER表中,则客户记录的审核日志将保存在CUSTOMER_AUD表中。

NHibernate Envers does a good job of creating an Audit Log whenever an entity is Updated/Deleted. Basically it creates an Audit table for each auditable entity and write a snapshot of the data into the Audit table. For e.g. if Customer records are saved in CUSTOMER table then audit log for Customer records will be saved in CUSTOMER_AUD table.

在我的一个项目中,我们使用Entity Framework 6.1。我已经搜索并查看了各种备选方案,例如 AuditDBContext EntityFramework Extensions ,但没有一个提供类似于NHibernate Envers的开箱解决方案。

In one of my projects we are using Entity Framework 6.1. I have searched and looked at various alternatives like AuditDBContext and EntityFramework Extensions but none of them provide an out of box solution similar to NHibernate Envers.

我认为生成审核日志应该是一个很常见的要求,所以我的问题是,是否有任何外部解决方案的EF 6+生成类似于NHibernate Envers的审核日志?

I think generating an Audit Log should be a pretty common requirement, so my question is, whether there is any out of box solution for EF 6+ that generates the Audit Log similar to NHibernate Envers?

推荐答案

我最终使用实现自定义解决方案AuditDBContext

基本上,我使用 AuditDBContext 保留跟踪哪些属性已更改,然后用于将信息写入审核表。审核表格与主表格完全相反,其中包含两列:

Basically, I use the AuditDBContext to keep track of what properties have changed and then used that to write information to Audit tables. The audit tables exactly mirror the main tables with two additional columns:


  • REV_TYPE - 表示修订版本可以是添加/更新/删除 / li>
  • REV_ID - 表示该行的唯一修订版本号。

这篇关于NHibernate如实体框架6+的审核日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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