3
I am wanting to do the audit tables of my entities. At first I thought to overwrite the method SaveChanges. I also thought of writing a method that will be doing the audit on my repository base. Using both forms, I will have a single audit table for my entire system.
But for performance reasons I need each entity to have its log table.
What would be the best way to intercept the type of my entity so that I can save in the audit table of the same?
My code until then is like this:
public override int SaveChanges()
{
     var entriesAdicionadas = ChangeTracker.Entries().Where(e => e.State == EntityState.Added).ToList();
     var entriesModificadas = ChangeTracker.Entries().Where(e => e.State == EntityState.Modified).ToList();
     var entriesDeletadas = ChangeTracker.Entries().Where(e => e.State == EntityState.Deleted).ToList();
     foreach (var entry in entriesAdicionadas)
     {
     }
     int result = base.SaveChanges();
     foreach (var entry in entriesModificadas)
     {
         var nome = entry.Entity.GetType().Name;
     }
     base.SaveChanges();
     foreach (var entry in entriesDeletadas)
     {
         var nome = entry.Entity.GetType().Name;
     }
     return result;
}