From f60ca2d55d899eda0070ef25d416fbad21aeac65 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Sun, 6 Mar 2022 12:21:55 +0100 Subject: [PATCH] Fixed bug if multiple bulk inserts are used in the same batch --- .../Update/Internal/SqlServerModificationCommandBatch.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatch.cs b/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatch.cs index f5d82082d0d..2d2429f88c6 100644 --- a/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatch.cs +++ b/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatch.cs @@ -163,7 +163,14 @@ private void AppendBulkInsertCommandText(int lastIndex) if (resultsContainPositionMapping) { - ResultsPositionalMappingEnabled ??= new BitArray(CommandResultSet.Count); + if (ResultsPositionalMappingEnabled is null) + { + ResultsPositionalMappingEnabled = new BitArray(CommandResultSet.Count); + } + else + { + ResultsPositionalMappingEnabled.Length = CommandResultSet.Count; + } for (var i = lastIndex - _bulkInsertCommands.Count; i < lastIndex; i++) {