Two DbSets causing: 'object' does not contain a definition for 'AddAsync' error #768
-
|
Hi, my work does not allow me to post to github, so i can copy exact stack traces unfortunately. but ill do my best. Versions:
Context: My internal class AuditLogDbContext : DbContext
{
public DbSet<EfAuditLogEntity> EfAuditLogs => Set<EfAuditLogEntity>();
public DbSet<DbCommandAuditEntity> DbCommandAuditLogs => Set<DbCommandAuditEntity>();
}
// constructor and OnModelCreating (both empty)My startup configuration looks like: public static IHost UseAuditLogger(this IHost host)
{
Configuration.Setup()
.UseDbContext(cfg =>
{
cfg.DbContextBuilder(_ =>
{
var scope = host.Services.CreateScope();
return scope.ServiceProvider.GetRequiredService<AuditLogDbContext>();
})
.DisposeDbContext(true)
.EntityBuilder(auditEvent =>
{
var eventEntries = new List<object?>();
var efEvent = auditEvent.GetEntityFrameworkEvent();
efEvent?.Entries.ForEach(entry =>
{
eventEntries.Add(new EfAuditLogEntity
{
Action = entry.Action,
AuditEventJson = auditEvent.ToJson(),
Database = efEvent.Database,
// so on a handful of other properties
});
});
var cmdEvent = auditEvent.GetCommandEntityFrameworkEvent();
if (cmdEvent is not null)
{
eventEntries.Add(new DbCommandAuditEntity
{
AuditEventJson = auditEvent.ToJson(),
Database = cmdEvent.Database,
// so on a handful of other properties
});
}
return eventEntries;
});
});
}Again, this all was working when my fail: Microsoft.EntityFrameworkCore.Update[10000]
An exception occurred in the database while saving changes for context type '<fullnamspace>.OperationsDbContext'.
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'AddSync'
at CallSite.Target(Closure, CallSite, Object, Object, CancellationToken)
at Audit.EntityFramework.Providers.DbContextDataProvider.AddEntityAsync(DbContext dbContext, Object entity, CancellationToken cancellationToken)
at Audit.EntityFramework.Providers.DbContextDataProvider.AddEntitiesAsync(DbContext dbContext, List`1 entities, CancellationToken cancellationToken)
at Audit.EntityFramework.Providers.DbContextDataProvider.InsertEventAsync(AuditEvent auditEvent, CancellationToken cancellationToken)
at Audit.Core.AuditScope.SaveEventAsync(Boolean forceInsert, CancellationToken cancellationToken)
at Audit.Core.AuditScope.EndAsync()
at Audit.Core.AuditScope.DisposeAsync()
...Which from debugging I tracked down to what I believe is this line: What is weird is looking at the Immediate window while debugging, I see that my My question is, the docs here seems to make it seem like we should be able to return two different models: https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.EntityFramework/README.md#different-audit-entities but is what i want to do actually supported? It seems like it should be based on the code and the documentation, but I cant seem to get it working no mater what i do. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Not sure how it worked before, but I made both my entity models and |
Beta Was this translation helpful? Give feedback.
Not sure how it worked before, but I made both my entity models and
AuditLogDbContextw/publicmodifiers, and it started working. So closing this out.