diff --git a/src/EFCore.Jet.Data/JetCommand.cs b/src/EFCore.Jet.Data/JetCommand.cs index ea3d02a..d722437 100644 --- a/src/EFCore.Jet.Data/JetCommand.cs +++ b/src/EFCore.Jet.Data/JetCommand.cs @@ -363,23 +363,30 @@ namespace EntityFrameworkCore.Jet.Data var command = (JetCommand) ((ICloneable) this).Clone(); command.CommandText = commandText; - for (var i = 0; i < usedParameterCount; i++) + if (_createProcedureExpression.IsMatch(command.CommandText)) { - command.Parameters.RemoveAt(0); + command.Parameters.Clear(); } - - var parameterIndices = parser.GetStateIndices( - new[] {'@', '?'}, - currentCommandStart, - commandDelimiter - currentCommandStart); - - while (command.Parameters.Count > parameterIndices.Count) + else { - command.Parameters.RemoveAt(parameterIndices.Count); + for (var i = 0; i < usedParameterCount && command.Parameters.Count > 0; i++) + { + command.Parameters.RemoveAt(0); + } + + var parameterIndices = parser.GetStateIndices( + new[] {'@', '?'}, + currentCommandStart, + commandDelimiter - currentCommandStart); + + while (command.Parameters.Count > parameterIndices.Count) + { + command.Parameters.RemoveAt(parameterIndices.Count); + } + + usedParameterCount += parameterIndices.Count; } - usedParameterCount += parameterIndices.Count; - commands.Add(command); }