NHibernate Envers like Audit Log with Entity Framework 6+

audit-logging entity-framework-6 orm

Question

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
4
6/17/2014 6:36:41 AM

Accepted Answer

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.
1
9/5/2014 8:15:34 AM

Popular Answer



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow