dotnet/efcore · error · InvalidOperationException

The result column for the property '{property}' cannot be ad

Error message

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

What it means

Thrown by StoredProcedure.AddResultColumn when a result column for the given property is already in _propertyResultColumns. Each property can have at most one result column on a stored procedure (used to read back generated/mutated values).

Source

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

    ///     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 StoredProcedureResultColumn? FindResultColumn(string propertyName)
        => _propertyResultColumns.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 StoredProcedureResultColumn AddResultColumn(string propertyName)
    {
        if (_propertyResultColumns.ContainsKey(propertyName))
        {
            throw new InvalidOperationException(
                RelationalStrings.StoredProcedureDuplicateResultColumn(
                    propertyName, ((IReadOnlyStoredProcedure)this).GetStoreIdentifier()?.DisplayName()));
        }

        var resultColumn = new StoredProcedureResultColumn(this, forRowsAffected: false, propertyName);
        _resultColumns.Add(resultColumn);
        _propertyResultColumns.Add(propertyName, resultColumn);

        return resultColumn;
    }

    /// <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 StoredProcedureResultColumn? FindRowsAffectedResultColumn()

View on GitHub (pinned to dbf9771522)

Solutions

  1. Guard with FindResultColumn(propertyName) before adding.
  2. Remove the duplicate .ResultColumn call.
  3. Configure each readback property once per sproc.

Example fix

// before
s.AddResultColumn("Id");
s.AddResultColumn("Id"); // throws

// after
if (s.FindResultColumn("Id") == null) s.AddResultColumn("Id");
Defensive patterns

Strategy: validation

Validate before calling

static StoredProcedureResultColumn AddResultColumnOnce(StoredProcedure sproc, string propertyName)
    => sproc.FindResultColumn(propertyName) ?? sproc.AddResultColumn(propertyName);

Prevention

When it happens

Trigger: StoredProcedure.cs:618-623: _propertyResultColumns.ContainsKey(propertyName) is true. Produced by calling .ResultColumn("Id") / AddResultColumn twice for the same property.

Common situations: Calling .ResultColumn(x => x.Id) twice; mixing lambda and string overloads; reconfiguring an INSERT sproc's identity readback and adding the column again.

Related errors


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