Deep Shah
Deep Shah

Reputation: 440

NHibernate Envers like Audit Log with Entity Framework 6+

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?

Upvotes: 5

Views: 2129

Answers (2)

Bilal Fazlani
Bilal Fazlani

Reputation: 6967

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.

Upvotes: 2

Deep Shah
Deep Shah

Reputation: 440

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.

Upvotes: 2

Related Questions