Instead of utilizing interceptors, consider running your updates in batches that'll remove invalid entries and re-try saving.
So for each "batch" of records you want to save:
bool isSaved = false;
do
{
try
{
await context.SaveChangesAsync();
isSaved = true;
}
catch (DbUpdateException ex)
{
foreach (var entry in ex.Entries)
entry.State = EntityState.Detached; // Remove from context so won't try saving again.
}
}
while (!isSaved);
Original Source: http://andreyzavadskiy.com/2016/09/22/ignoring-dbupdateexception-and-continue/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…