dotnet/efcore · error · InvalidOperationException
The result column '{column}' cannot be added to the stored p
Error message
The result column '{column}' cannot be added to the stored procedure '{sproc}' because another result column with this name already exists. What it means
Thrown when two result columns on the same stored procedure share the same store column name. The validator tracks names in a HashSet and rejects a duplicate add. Each result column must have a unique store name within a single sproc.
Source
Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:666
storeGeneratedProperties.Remove(property.Name);
}
}
var resultColumnNames = new HashSet<string>();
foreach (var resultColumn in sproc.ResultColumns)
{
IProperty? property = null!;
if (resultColumn.PropertyName != null
&& !properties.TryGetValue(resultColumn.PropertyName, out property))
{
throw new InvalidOperationException(
RelationalStrings.StoredProcedureResultColumnNotFound(
resultColumn.PropertyName, entityType.DisplayName(), storeObjectIdentifier.DisplayName()));
}
if (!resultColumnNames.Add(resultColumn.Name))
{
throw new InvalidOperationException(
RelationalStrings.StoredProcedureDuplicateResultColumnName(
resultColumn.Name, storeObjectIdentifier.DisplayName()));
}
if (resultColumn.PropertyName == null)
{
continue;
}
switch (storeObjectIdentifier.StoreObjectType)
{
case StoreObjectType.InsertStoredProcedure:
case StoreObjectType.UpdateStoredProcedure:
if (!storeGeneratedProperties.ContainsKey(property.Name))
{
throw new InvalidOperationException(
RelationalStrings.StoredProcedureResultColumnNotGenerated(
entityType.DisplayName(), resultColumn.PropertyName, storeObjectIdentifier.DisplayName()));View on GitHub (pinned to dbf9771522)
Solutions
- Remove the duplicate HasResultColumn call.
- Rename one of the result columns so the store names differ.
- Consolidate the two mappings into a single result column.
Example fix
// before
sp.HasResultColumn("Id");
sp.HasResultColumn("Id"); // duplicate
// after
sp.HasResultColumn("Id"); 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 rc in s.ResultColumns)
if (!seen.Add(rc.Name)) throw new InvalidOperationException($"Duplicate result column {rc.Name} on {s.GetStoreIdentifier().Name}");
}
} Try / catch
try { _ = ctx.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains("another result column with this name already exists")) { /* remove the duplicate result column */ } Prevention
- Avoid declaring the same result column twice; build result-column config from a single source.
When it happens
Trigger: Two .HasResultColumn("Id") calls on the same sproc; mapping the same store column name twice by mistake.
Common situations: Accidental duplicate config lines; merging two builders that both declare the same result column.
Related errors
- No property named '{property}' found on the entity type '{en
- The property '{entityType}.{property}' is mapped to a result
- The property '{entityType}.{property}' is mapped to a result
- The parameter '{parameter}' cannot be added to the stored pr
- The entity type '{entityType}' was configured to use some st
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/cfd58646f6d315f9.
Report an issue: GitHub.