dotnet / dotnet/efcore

Consider cancelling the command in SaveChanges when an error occurs

Open
#30,182 2 comments 0 reactions 0 assignees View on GitHub
area-perf area-save-changes needs-design
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

We currently limit the SaveChanges batch size (42 in SQL Server), among other things because if an error occurs (e.g. unique constraint), we don't want to continue sending a huge amount of useless data that will get rolled back anyway. The PG provider, by the way, has no such upper limit (see https://github.com/npgsql/efcore.pg/issues/2630 for a recent complaint about this). Limiting the max batch size sacrifices performance for the good case (more roundtrips when no errors occur), so that the bad case is faster.

An alternative approach may be to simply attempt cancellation of the query when we see an error. FWIW this is what Dapper does, IIRC.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.