dotnet/efcore · error · InvalidOperationException
The parameter for the property '{property}' cannot be added
Error message
The parameter for the property '{property}' cannot be added to the stored procedure '{sproc}' because another parameter for this property already exists. What it means
Thrown by StoredProcedure.AddParameter when a current-value parameter for the given property name is already present in _currentValueParameters. Each property can have at most one current-value parameter on a stored procedure.
Source
Thrown at src/EFCore.Relational/Metadata/Internal/StoredProcedure.cs:513
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual StoredProcedureParameter? FindParameter(string propertyName)
=> _currentValueParameters.GetValueOrDefault(propertyName);
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual StoredProcedureParameter AddParameter(string propertyName)
{
if (_currentValueParameters.ContainsKey(propertyName))
{
throw new InvalidOperationException(
RelationalStrings.StoredProcedureDuplicateParameter(
propertyName, ((IReadOnlyStoredProcedure)this).GetStoreIdentifier()?.DisplayName()));
}
var parameter = new StoredProcedureParameter(this, rowsAffected: false, propertyName, originalValue: false);
_parameters.Add(parameter);
_currentValueParameters.Add(propertyName, parameter);
return parameter;
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual StoredProcedureParameter? FindOriginalValueParameter(string propertyName)View on GitHub (pinned to dbf9771522)
Solutions
- Guard with FindParameter(propertyName) before calling AddParameter.
- Remove the duplicate .Parameter/.AddParameter call for the same property.
- If reconfiguring, call the builder only once per property.
Example fix
// before
s.AddParameter("Name");
s.AddParameter("Name"); // throws
// after
if (s.FindParameter("Name") == null) s.AddParameter("Name"); Defensive patterns
Strategy: validation
Validate before calling
static StoredProcedureParameter AddParameterOnce(StoredProcedure sproc, string propertyName)
=> sproc.FindParameter(propertyName) ?? sproc.AddParameter(propertyName); Prevention
- Always guard AddParameter with FindParameter.
- Avoid mixing lambda and string parameter overloads for the same property.
When it happens
Trigger: StoredProcedure.cs:511-516: _currentValueParameters.ContainsKey(propertyName) is true. Produced by calling .AddParameter("X") twice, or by EF automatically adding a parameter and then user code adding it again.
Common situations: Calling .Parameter(x => x.Name) twice; mixing the lambda and string overloads for the same property; scaffolding a sproc and then re-adding parameters manually.
Related errors
- The original value parameter for the property '{property}' c
- The rows affected parameter cannot be added to the stored pr
- The result column for the property '{property}' cannot be ad
- The rows affected result column cannot be added to the store
- '{facet}' cannot be configured for the parameter '{parameter
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/d6583fcbb8273333.
Report an issue: GitHub.