Does anyone know how to override SaveChangesAsync? I know a similar question was posted but there was no answer. I have the following code below:
public override async Task<int> SaveChangesAsync()
{
PerformFurtherValidations();
return await base.SaveChangesAsync();
}
During Build I get the following error message:
Error SaveChangesAsync(): return type must be
System.Threading.Tasks.Task<int>
to match overridden memberSystem.Data.Entity.DbContext.SaveChangesAsync()
Old question, but I had a similar problem and resolved it with the following code:
public override async Task<int> SaveChangesAsync()
{
foreach (var history in this.ChangeTracker.Entries()
.Where(e => e.Entity is IModificationHistory && (e.State == EntityState.Added ||
e.State == EntityState.Modified))
.Select(e => e.Entity as IModificationHistory)
)
{
history.DateModified = DateTime.Now;
if (history.DateCreated <= DateTime.MinValue)
{
history.DateCreated = DateTime.Now;
}
}
int result = await base.SaveChangesAsync();
foreach (var history in this.ChangeTracker.Entries()
.Where(e => e.Entity is IModificationHistory)
.Select(e => e.Entity as IModificationHistory))
{
history.IsDirty = false;
}
return result;
}
The custom SaveChangesAsync() allows me to tweak the dirty flag, date created and date modified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With