{"record":{"id":"cfd58646f6d315f9","repo":"dotnet/efcore","slug":"the-result-column-column-cannot-be-added-to-th","errorCode":null,"errorMessage":"The result column '{column}' cannot be added to the stored procedure '{sproc}' because another result column with this name already exists.","messagePattern":"The result column '(.+?)' cannot be added to the stored procedure '(.+?)' because another result column with this name already exists\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":666,"sourceCode":"                storeGeneratedProperties.Remove(property.Name);\n            }\n        }\n\n        var resultColumnNames = new HashSet<string>();\n        foreach (var resultColumn in sproc.ResultColumns)\n        {\n            IProperty? property = null!;\n            if (resultColumn.PropertyName != null\n                && !properties.TryGetValue(resultColumn.PropertyName, out property))\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.StoredProcedureResultColumnNotFound(\n                        resultColumn.PropertyName, entityType.DisplayName(), storeObjectIdentifier.DisplayName()));\n            }\n\n            if (!resultColumnNames.Add(resultColumn.Name))\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.StoredProcedureDuplicateResultColumnName(\n                        resultColumn.Name, storeObjectIdentifier.DisplayName()));\n            }\n\n            if (resultColumn.PropertyName == null)\n            {\n                continue;\n            }\n\n            switch (storeObjectIdentifier.StoreObjectType)\n            {\n                case StoreObjectType.InsertStoredProcedure:\n                case StoreObjectType.UpdateStoredProcedure:\n                    if (!storeGeneratedProperties.ContainsKey(property.Name))\n                    {\n                        throw new InvalidOperationException(\n                            RelationalStrings.StoredProcedureResultColumnNotGenerated(\n                                entityType.DisplayName(), resultColumn.PropertyName, storeObjectIdentifier.DisplayName()));","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L648-L684","documentation":"Thrown in the same result-column loop when two result columns share the same store Name (RelationalModelValidator.cs:664-669). A HashSet<string> resultColumnNames tracks seen names; Add returns false on a duplicate. Result columns must have unique store names so EF can disambiguate values returned by the sproc.","triggerScenarios":"Configuring two result columns that map to the same store column name (e.g., both defaulting to 'Id', or explicitly set HasResultColumn(...).HasName(\"Id\") twice). Often from copy-paste or from a property rename where both bindings fell back to the same column.","commonSituations":"Two properties both named with column 'Id' after a refactor; scaffolding a sproc whose result set has duplicate aliases; an owned/complex property whose column collided with the owner's.","solutions":["Give each result column a distinct store name: sp.HasResultColumn(x => x.Foo).HasColumnName(\"foo_col\") and ensure no two share it.","Remove the duplicate HasResultColumn call.","If the DB result set truly has duplicates, alias them in the sproc so each column name is unique."],"exampleFix":"// before\nsp.HasResultColumn(x => x.RowVersion).HasColumnName(\"ts\");\nsp.HasResultColumn(x => x.Timestamp).HasColumnName(\"ts\"); // duplicate store name\n\n// after\nsp.HasResultColumn(x => x.RowVersion).HasColumnName(\"row_version\");\nsp.HasResultColumn(x => x.Timestamp).HasColumnName(\"row_ts\");","handlingStrategy":"validation","validationCode":"foreach (var et in modelBuilder.Model.GetEntityTypes())\n{\n    foreach (var sproc in new[] { et.GetInsertStoredProcedure(), et.GetUpdateStoredProcedure(), et.GetDeleteStoredProcedure() })\n    {\n        if (sproc is null) continue;\n        var names = sproc.ResultColumns.Select(rc => rc.Name).ToList();\n        if (names.Count != names.Distinct().Count())\n            throw new InvalidOperationException($\"Duplicate result-column store names on sproc '{sproc.GetStoreIdentifier().DisplayName}': {string.Join(\", \", names)}.\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try { _ = ctx.Model; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"another result column with this name already exists\"))\n{\n    logger.LogError(\"Duplicate result-column name on sproc. {Msg}\", ex.Message);\n    throw;\n}","preventionTips":["Set distinct HasColumnName(...) on each HasResultColumn when property names could collide.","Keep a single IEntityTypeConfiguration block for each sproc so column names are auditable in one place.","Avoid copy-pasting result-column blocks across sprocs."],"tags":["efcore","relational","stored-procedure","result-column","duplicate","model-validation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}