dotnet/efcore · error · InvalidOperationException

The original value parameter for the property '{property}' c

Error message

The original value parameter for the property '{property}' cannot be added to the stored procedure '{sproc}' because another original value parameter for this property already exists.

What it means

Thrown by StoredProcedure.AddOriginalValueParameter when an original-value parameter for the property is already in _originalValueParameters. A property may have at most one original-value parameter on a stored procedure (used for optimistic concurrency on UPDATE).

Source

Thrown at src/EFCore.Relational/Metadata/Internal/StoredProcedure.cs:544

    ///     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)
        => _originalValueParameters.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 AddOriginalValueParameter(string propertyName)
    {
        if (_originalValueParameters.ContainsKey(propertyName))
        {
            throw new InvalidOperationException(
                RelationalStrings.StoredProcedureDuplicateOriginalValueParameter(
                    propertyName, ((IReadOnlyStoredProcedure)this).GetStoreIdentifier()?.DisplayName()));
        }

        var parameter = new StoredProcedureParameter(this, rowsAffected: false, propertyName, originalValue: true);
        _parameters.Add(parameter);
        _originalValueParameters.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? FindRowsAffectedParameter()

View on GitHub (pinned to dbf9771522)

Solutions

  1. Guard with FindOriginalValueParameter(propertyName) before adding.
  2. Remove the duplicate original-value parameter configuration.
  3. Configure concurrency-token original values once per sproc.

Example fix

// before
s.AddOriginalValueParameter("RowVersion");
s.AddOriginalValueParameter("RowVersion"); // throws

// after
if (s.FindOriginalValueParameter("RowVersion") == null) s.AddOriginalValueParameter("RowVersion");
Defensive patterns

Strategy: validation

Validate before calling

static StoredProcedureParameter AddOriginalValueParameterOnce(StoredProcedure sproc, string propertyName)
    => sproc.FindOriginalValueParameter(propertyName) ?? sproc.AddOriginalValueParameter(propertyName);

Prevention

When it happens

Trigger: StoredProcedure.cs:542-547: _originalValueParameters.ContainsKey(propertyName) is true. Produced by calling .OriginalValueParameter("X") / .AddOriginalValueParameter twice, or configuring the same concurrency token's original value twice.

Common situations: Declaring .OriginalValueParameter(x => x.RowVersion) twice; mixing lambda and string overloads; re-running sproc configuration without clearing.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/64881a9e28114ed7. Report an issue: GitHub.