1

I'm using entity framework for first time. I have to create many entities(tables) with using of Entity Framework 6, is there any way how automatically create history table for all the entities and insert old version of a row into EntityHistory table whenever is row changed?

Josef
  • 43
  • 7

2 Answers2

0

If i am not wrong we can manage it With the help of Entity Framework Snapshot History. Click here to view the similar answer.

Samim Hussain
  • 396
  • 5
  • 14
0

Disclaimer: I'm the owner of the project Entity Framework Plus

Documentations: EF+ Audit

This library allows you to audit & save information in a database with the AutoSavePreAction Action.

AuditManager.DefaultConfiguration.AutoSavePreAction = (context, audit) =>
     // ADD "Where(x => x.AuditEntryID == 0)" to allow multiple SaveChanges with same Audit
     (context as EntityContext).AuditEntries.AddRange(audit.Entries);

// using Z.EntityFramework.Plus; // Don't forget to include this.

var ctx = new EntityContext();
// ... ctx changes ...

var audit = new Audit();
audit.CreatedBy = "ZZZ Projects"; // Optional
ctx.SaveChanges(audit);

// Access to all auditing information
var entries = audit.Entries;
foreach(var entry in entries)
{
    foreach(var property in entry.Properties)
    {
    }
}
Jonathan Magnan
  • 10,874
  • 2
  • 38
  • 60