NHibernate Envers like Audit Log with Entity Framework 6+

匆匆过客 提交于 2019-12-23 13:06:10

问题


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.

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.

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?


回答1:


Also take a look at https://github.com/bilal-fazlani/tracker-enabled-dbcontext

https://www.nuget.org/packages/TrackerEnabledDbContext

Its a bit different, but worth taking a look at.




回答2:


I ended up implementing a custom solution using the 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 - That indicates the revision type could be Add/Update/Delete
  • REV_ID - Indicates a unique revision id for that row.


来源:https://stackoverflow.com/questions/24257164/nhibernate-envers-like-audit-log-with-entity-framework-6

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