I'm trying to implement the Audit.EntityFramework.Core
package from the Audit.Net repository but am running into some difficulty. I'm unable to save changes or target a different database. I've modified my SaveChanges
and SaveChangesAsync
function to call the Audit.Net
DbContextHelper
class's save functions but I'm missing something.
Is there a way to do the following?
- Target another database for storing audit data using an audit
DbContext
that inherits from theDbContext
I'm trying to audit?public class MyDbContext : DbContext {} //Types defined here public class AuditDbContext : MyDbContext {} //This context stores audit data into a different DB
- Not require mapping between the type and its audited type when setting up a global connection? (I'm trying to avoid calling
AuditTypeMapper
explicitly for each type with a model that's currently undergoing a lot of change).//MyDbContext has different connection string than AuditDbContext Audit.Core.Configuration.Setup() .UseEntityFramework(x => x .UseDbContext<AuditDbContext>());
I've tried code that resembles the following but get runtime errors on SaveChanges
that indicate that there is no model set up. Adding a migration for the AuditDbContext
didn't help.