EF6 Code First Audit Table Per Entity

c# ef-code-first entity-framework entity-framework-6 sql-server

Question

I believe that EF offers a more straightforward solution to one of my requirements than what we do now.

Essentially, as a requirement for auditing, I need to create two tables: the entity's table itself and a table that is identical to the original entity's table but has three additional columns: an FK back to the original entity's table, a description (such as "Modified," "Added," or "Deleted"), and an XML column that will contain a serialized version of the entity's state.

The audit tables are currently created by manually adding the entities (currently inherit from an AuditableEntity class, and developers must manually check that other fields match the original entity) and using migrations to add T-SQL triggers to the entity tables to update the data in the audit tables on any insert, update, or delete.

Instead of manually syncing the audit tables with the entity tables, I'd prefer to find a way to have EF do it automatically. I'd also prefer to use an interceptor or a similar tool to update the audit table whenever an entity is added, updated, or deleted rather than using triggers. Does anyone have experience with this or know if it is even possible? My previous best effort was a single, shared audit history table, which wasn't too bad.

1
3
6/10/2015 9:20:49 PM

Accepted Answer

ZZZ_tmp
1
2/23/2018 7:13:10 PM

Popular Answer

ZZZ_tmp


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