{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L648-L684","documentation":"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.","triggerScenarios":"Two .HasResultColumn(\"Id\") calls on the same sproc; mapping the same store column name twice by mistake.","commonSituations":"Accidental duplicate config lines; merging two builders that both declare the same result column.","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."],"exampleFix":"// before\nsp.HasResultColumn(\"Id\");\nsp.HasResultColumn(\"Id\"); // duplicate\n\n// after\nsp.HasResultColumn(\"Id\");","handlingStrategy":"validation","validationCode":"foreach (var et in modelBuilder.Model.GetEntityTypes())\n{\n    foreach (var s in new[] { et.GetInsertStoredProcedure(), et.GetUpdateStoredProcedure(), et.GetDeleteStoredProcedure() }.Where(s => s != null))\n    {\n        var seen = new HashSet<string>();\n        foreach (var rc in s.ResultColumns)\n            if (!seen.Add(rc.Name)) throw new InvalidOperationException($\"Duplicate result column {rc.Name} on {s.GetStoreIdentifier().Name}\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try { _ = ctx.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"another result column with this name already exists\")) { /* remove the duplicate result column */ }","preventionTips":["Avoid declaring the same result column twice; build result-column config from a single source."],"tags":["ef-core","stored-procedures","result-column","duplicate","model-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}