diff --git a/src/Npgsql.EntityFrameworkCore.PostgreSQL/Update/Internal/NpgsqlModificationCommandBatch.cs b/src/Npgsql.EntityFrameworkCore.PostgreSQL/Update/Internal/NpgsqlModificationCommandBatch.cs index 294f7018488f5ddd785419a33c3d2dfa33f62ba1..01486dde5befe9669e0bb11d21afcbd049a0161f 100644 --- a/src/Npgsql.EntityFrameworkCore.PostgreSQL/Update/Internal/NpgsqlModificationCommandBatch.cs +++ b/src/Npgsql.EntityFrameworkCore.PostgreSQL/Update/Internal/NpgsqlModificationCommandBatch.cs @@ -53,6 +53,7 @@ public class NpgsqlModificationCommandBatch : ReaderModificationCommandBatch { const int DefaultBatchSize = 1000; readonly int _maxBatchSize; + long _parameterCount; public NpgsqlModificationCommandBatch( [NotNull] IRelationalCommandBuilderFactory commandBuilderFactory, @@ -68,8 +69,21 @@ public class NpgsqlModificationCommandBatch : ReaderModificationCommandBatch _maxBatchSize = maxBatchSize ?? DefaultBatchSize; } + protected override int GetParameterCount() => (int)_parameterCount; + protected override bool CanAddCommand(ModificationCommand modificationCommand) - => ModificationCommands.Count < _maxBatchSize; + { + if (ModificationCommands.Count >= _maxBatchSize) + return false; + + var newParamCount = _parameterCount + modificationCommand.ColumnModifications.Count; + + if (newParamCount > int.MaxValue) + return false; + + _parameterCount = newParamCount; + return true; + } protected override bool IsCommandTextValid() => true;