dotnet/efcore · error · InvalidOperationException
The parameter '{parameter}' cannot be added to the stored pr
Error message
The parameter '{parameter}' cannot be added to the stored procedure '{sproc}' because another parameter with this name already exists. What it means
Thrown when two parameters on the same stored procedure share the same store parameter name. The validator tracks names in a HashSet and rejects a duplicate add. Each parameter must have a unique store name within a single sproc, including the implicit current-value and original-value forms of the same property.
Source
Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:782
property.GetAfterSaveBehavior()));
}
break;
case StoreObjectType.DeleteStoredProcedure:
break;
default:
Check.DebugFail("Unexpected stored procedure type: " + storeObjectIdentifier.StoreObjectType);
break;
}
}
}
}
if (!parameterNames.Add(parameter.Name))
{
throw new InvalidOperationException(
RelationalStrings.StoredProcedureDuplicateParameterName(
parameter.Name, storeObjectIdentifier.DisplayName()));
}
if (parameter.PropertyName == null)
{
continue;
}
switch (storeObjectIdentifier.StoreObjectType)
{
case StoreObjectType.InsertStoredProcedure:
case StoreObjectType.UpdateStoredProcedure:
if (parameter.Direction != ParameterDirection.Input
&& !storeGeneratedProperties.Remove(property!.Name))
{
if (sproc.Parameters.Any(p => p.PropertyName == property.Name
&& p.ForOriginalValue != parameter.ForOriginalValueView on GitHub (pinned to dbf9771522)
Solutions
- Give one parameter a distinct explicit name via the HasParameter("uniqueName") overload.
- Remove the duplicate parameter.
- Ensure original-value and current-value parameters for the same property use different store names.
Example fix
// before
sp.HasParameter("RowVersion");
sp.HasOriginalValueParameter("RowVersion"); // same default name
// after
sp.HasParameter("RowVersion");
sp.HasOriginalValueParameter("RowVersion_Original"); Defensive patterns
Strategy: validation
Validate before calling
foreach (var et in modelBuilder.Model.GetEntityTypes())
{
foreach (var s in new[] { et.GetInsertStoredProcedure(), et.GetUpdateStoredProcedure(), et.GetDeleteStoredProcedure() }.Where(s => s != null))
{
var seen = new HashSet<string>();
foreach (var p in s.Parameters)
if (!seen.Add(p.Name)) throw new InvalidOperationException($"Duplicate param {p.Name} on {s.GetStoreIdentifier().Name}");
}
} Try / catch
try { _ = ctx.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains("another parameter with this name already exists")) { /* rename or remove the duplicate parameter */ } Prevention
- When binding both current and original values of one property, give the original-value param a distinct store name.
When it happens
Trigger: Two .HasParameter("Name") calls; an original-value and current-value parameter of the same property resolving to the same store name without explicit renaming.
Common situations: Explicitly naming two parameters identically; declaring both a current and original value parameter for a property using the same default name.
Related errors
- The result column '{column}' cannot be added to the stored p
- No property named '{property}' found on the entity type '{en
- Original value parameter '{parameter}' is not allowed on ins
- Current value parameter '{parameter}' is not allowed on dele
- Input parameter '{parameter}' of insert stored procedure '{s
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/11d5528334af90c0.
Report an issue: GitHub.