When SaveChanges fails (eg. no permission to save Detail-Table), then the Detail-Entity is reloaded (Changes reverted), AuditLogs will be inserted at the next SaveChanges.
Is there a useful workaround for that usecase? I could try to remove all pending AuditLogs associated with that Detail-Entity, but I feel like that would be the job of the TrackerContext :)
var master = dbcontext.Masters.FirstOrDefault();
var detail = master.Detail.FirstOrDefault();
detail.TextColumn = "This ist a Test change, that should not show up!";
try
{
dbcontext.SaveChanges();
}
catch (DbUpdateException ex)
{
SqlException innerException = ex.InnerException?.InnerException as SqlException;
if (innerException != null && (innerException.Number == 229 || innerException.Number == 230))
{
// Show MessageBox: No Permission
// User closes Edit-Dialog, does not save Detail-Entity, Detail-Entity gets refreshed
// (I know, this is not the right place to put that code, but it illustrates what the user could do)
dbcontext.Entry(detail).Reload();
// User SavesChanges
dbcontext.SaveChanges();
}
else
throw ex;
}
When SaveChanges fails (eg. no permission to save Detail-Table), then the Detail-Entity is reloaded (Changes reverted), AuditLogs will be inserted at the next SaveChanges.
Is there a useful workaround for that usecase? I could try to remove all pending AuditLogs associated with that Detail-Entity, but I feel like that would be the job of the TrackerContext :)