Skip to content

Commit eb10f86

Browse files
committed
Reuse parameters instead of copying them
1 parent 2fd9868 commit eb10f86

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

src/NHibernate/AdoNet/GenericBatchingBatcher.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@ public void Append(DbParameterCollection parameters)
176176
_batcher.CurrentCommandParameterTypes);
177177
UpdateCommandParameters(command, parameters);
178178
_batchCommand.CommandText += $"{_batcher.StatementTerminator}{command.CommandText}";
179-
foreach (DbParameter parameter in command.Parameters)
179+
while (command.Parameters.Count > 0)
180180
{
181-
_batchCommand.Parameters.Add(CopyParameter(_batchCommand, parameter));
181+
var pram = command.Parameters[0];
182+
command.Parameters.RemoveAt(0);
183+
_batchCommand.Parameters.Add(pram);
182184
}
183185
command.Dispose();
184186
}
@@ -222,23 +224,6 @@ private void UpdateCommandParameters(DbCommand command, DbParameterCollection pa
222224
}
223225
}
224226

225-
private DbParameter CopyParameter(DbCommand command, DbParameter parameter)
226-
{
227-
var copy = command.CreateParameter();
228-
copy.DbType = parameter.DbType;
229-
copy.IsNullable = parameter.IsNullable;
230-
copy.ParameterName = parameter.ParameterName;
231-
copy.Value = parameter.Value;
232-
copy.Direction = parameter.Direction;
233-
copy.Precision = parameter.Precision;
234-
copy.Scale = parameter.Scale;
235-
copy.Size = parameter.Size;
236-
copy.SourceVersion = parameter.SourceVersion;
237-
copy.SourceColumn = parameter.SourceColumn;
238-
copy.SourceColumnNullMapping = parameter.SourceColumnNullMapping;
239-
return copy;
240-
}
241-
242227
private SqlString PrepareSqlString(SqlString sql)
243228
{
244229
if (_batchCommand == null)

0 commit comments

Comments
 (0)