Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
¿Cómo me dirijo a otra base de datos con tracker-enabled-dbcontext?

Estoy tratando de implementar el paquete tracker-enabled-dbcontext del repositorio de git documentaion y tracker-enabled-dbcontext Pero no puedo cambiar los cambios guardados para apuntar a una base de datos diferente. He modificado mis SaveChanges

 public class MyDBContext : DbContext, IUnitOfWork {} public class MacsAuditDbContext : TrackerEnabledDbContext.TrackerContext {}

en MiContextoDB

 public override int SaveChanges() { DateTime nowAuditDate = DateTime.Now; IEnumerable<System.Data.Entity.Infrastructure.DbEntityEntry<DomainEntity>> changeSet = ChangeTracker.Entries<DomainEntity>(); if (changeSet != null) { foreach (System.Data.Entity.Infrastructure.DbEntityEntry<DomainEntity> entry in changeSet) { switch (entry.State) { case EntityState.Added: entry.Entity.Created = nowAuditDate; entry.Entity.Modified = nowAuditDate; break; case EntityState.Modified: entry.Entity.Modified = nowAuditDate; break; } } } using (MacsAuditDbContext db = new MacsAuditDbContext()) { db.SaveChanges(); } return base.SaveChanges(); }

en mi clase de inicio

 public class Startup { public void Configuration(IAppBuilder app) { AuthConfig.Register(app); GlobalConfiguration.Configuration .UseSqlServerStorage("MacsAuditDbContext"); } }

Pero todavía no puedo guardar los registros de auditoría en la base de datos de destino (secundaria). mi dominio se completa guardando mi base de datos principal pero no los registros de auditoría. ¿Quiero pasar MyDBContext a MacsAuditDbContext? O estoy haciendo algo mal? por favor, ayúdame.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede intentar aprovechar el evento OnAuditLogGenerated . Algo así:

 public sealed class MyDBContext : TrackerContext { public MyDBContext () { OnAuditLogGenerated += SaveToAnotherDb; } private void SaveToAnotherDb(object? sender, AuditLogGeneratedEventArgs args) { var auditLog = args.Log; using (MacsAuditDbContext db = new MacsAuditDbContext()) { db.AuditLog.Add(auditLog); db.SaveChanges(); } //skips saving to local database args.SkipSavingLog = true; } protected override void Dispose(bool disposing) { OnAuditLogGenerated -= SaveToAnotherDb; base.Dispose(disposing); } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!