{"record":{"id":"9a6f02917e3b3306","repo":"dotnet/efcore","slug":"the-stored-procedure-sproc-cannot-be-configure","errorCode":null,"errorMessage":"The stored procedure '{sproc}' cannot be configured to return the rows affected because a rows affected parameter or a rows affected result column for this stored procedure already exists.","messagePattern":"The stored procedure '(.+?)' cannot be configured to return the rows affected because a rows affected parameter or a rows affected result column for this stored procedure already exists\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/StoredProcedure.cs","lineNumber":446,"sourceCode":"    public virtual bool IsRowsAffectedReturned\n    {\n        get => _isRowsAffectedReturned;\n        set => SetIsRowsAffectedReturned(value);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual bool SetIsRowsAffectedReturned(bool rowsAffectedReturned)\n    {\n        EnsureMutable();\n\n        if (_rowsAffectedParameter != null || _rowsAffectedResultColumn != null)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.StoredProcedureRowsAffectedReturnConflictingParameter(\n                    ((IReadOnlyStoredProcedure)this).GetStoreIdentifier()?.DisplayName()));\n        }\n\n        _isRowsAffectedReturned = rowsAffectedReturned;\n\n        return rowsAffectedReturned;\n    }\n\n    private static void UpdateOverrides(\n        StoreObjectIdentifier oldId,\n        StoreObjectIdentifier? newId,\n        IConventionEntityType entityType)\n    {\n        if (oldId == newId)\n        {\n            return;\n        }","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/StoredProcedure.cs#L428-L464","documentation":"Thrown when SetIsRowsAffectedReturned(true) is called on a stored procedure mapping that already has a rows-affected parameter or a rows-affected result column configured. EF exposes exactly one channel for rows-affected, so requesting the return variant on top of an existing one is ambiguous.","triggerScenarios":"StoredProcedure.SetIsRowsAffectedReturned(true) when _rowsAffectedParameter != null || _rowsAffectedResultColumn != null. Happens after calling RowsAffectedParameter(...), RowsAffectedResultColumn(...), and then trying to enable IsRowsAffectedReturned.","commonSituations":"Switching a stored procedure mapping from a rows-affected parameter to a return-value approach without first removing the parameter; building the mapping programmatically and adding multiple rows-affected channels; copy/paste of configuration calls.","solutions":["Remove the existing rows-affected parameter/result column before enabling IsRowsAffectedReturned.","Choose a single rows-affected mechanism (parameter, result column, or return value) and configure only that one.","Clear the stored procedure mapping and rebuild it with the desired rows-affected channel."],"exampleFix":"// before\nupdateSproc.RowsAffectedParameter(\"rc\");\nupdateSproc.IsRowsAffectedReturned = true; // throws\n\n// after: pick one mechanism\nupdateSproc.IsRowsAffectedReturned = true;\n// (do not also add a rows-affected parameter)","handlingStrategy":"validation","validationCode":"// Before enabling IsRowsAffectedReturned, ensure no parameter or result column exists.\nif (sproc.RowsAffectedParameter is null && sproc.RowsAffectedResultColumn is null)\n    sproc.IsRowsAffectedReturned = true;\nelse\n    throw new InvalidOperationException(\n        \"Cannot enable rows-affected return: a rows-affected parameter or result column already exists.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose exactly one rows-affected channel (parameter, result column, or return value) per stored procedure mapping.","Configure rows-affected once, declaratively, and avoid mixing fluent calls.","Add a unit test that asserts the mapping has at most one rows-affected channel."],"tags":["ef-core","relational-metadata","stored-procedure","rows-affected","configuration-conflict"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}