❔ EFCore Interceptor problem
In the MS documentation I see they're using the SaveChanges interceptor as:
I'm trying to do the same but I get an error and I presume it's because of the value task:
The error is that it cannot convert result to
public async ValueTask<InterceptionResult<int>> SavingChangesAsync(
DbContextEventData eventData,
InterceptionResult<int> result,
CancellationToken cancellationToken = default)
{
_audit = CreateAudit(eventData.Context);
using var auditContext = new AuditContext(_connectionString);
auditContext.Add(_audit);
await auditContext.SaveChangesAsync();
return result;
}public async ValueTask<InterceptionResult<int>> SavingChangesAsync(
DbContextEventData eventData,
InterceptionResult<int> result,
CancellationToken cancellationToken = default)
{
_audit = CreateAudit(eventData.Context);
using var auditContext = new AuditContext(_connectionString);
auditContext.Add(_audit);
await auditContext.SaveChangesAsync();
return result;
}I'm trying to do the same but I get an error and I presume it's because of the value task:
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData, InterceptionResult<int> result,
CancellationToken cancellationToken = new CancellationToken())
{
if (eventData.Context is null) return result;
foreach (var entry in eventData.Context.ChangeTracker.Entries())
{
if (entry is not { State: EntityState.Deleted, Entity: ISoftDelete delete }) continue;
entry.State = EntityState.Modified;
delete.DeletedAt = DateTime.Now;
}
return result;
} public override ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData, InterceptionResult<int> result,
CancellationToken cancellationToken = new CancellationToken())
{
if (eventData.Context is null) return result;
foreach (var entry in eventData.Context.ChangeTracker.Entries())
{
if (entry is not { State: EntityState.Deleted, Entity: ISoftDelete delete }) continue;
entry.State = EntityState.Modified;
delete.DeletedAt = DateTime.Now;
}
return result;
}The error is that it cannot convert result to
ValueTask...ValueTask.... how does the MS example work though...