{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Metadata/Internal/StoredProcedure.cs#L428-L464","documentation":"Thrown by StoredProcedure.SetIsRowsAffectedReturned when you try to mark a stored procedure as returning rows-affected via its return value, but a rows-affected OUTPUT parameter or a rows-affected result column already exists on that sproc. EF enforces one single mechanism for capturing rows affected per stored procedure.","triggerScenarios":"StoredProcedure.cs:444-449: _rowsAffectedParameter != null || _rowsAffectedResultColumn != null when SetIsRowsAffectedReturned(true) is called. Reached via InsertStoredProcedure().AddRowsAffectedParameter()/AddRowsAffectedResultColumn() followed by .ReturnsRowsAffected() (or setting IsRowsAffectedReturned).","commonSituations":"Fluent config that mixes .AddRowsAffectedParameter() with .ReturnsRowsAffected(); scaffolding then manually re-configuring the sproc; copying sproc config and stacking two rows-affected mechanisms.","solutions":["Pick exactly one rows-affected mechanism: an output parameter, a result column, or the return value — and remove the others.","If you already added a parameter/column, do not also call ReturnsRowsAffected().","Reset the sproc mapping and reconfigure from scratch with a single approach."],"exampleFix":"// before\nvar s = eb.InsertStoredProcedure();\ns.AddRowsAffectedParameter();\ns.ReturnsRowsAffected(); // throws - two mechanisms\n\n// after\nvar s = eb.InsertStoredProcedure();\ns.ReturnsRowsAffected();","handlingStrategy":"validation","validationCode":"static void EnableRowsAffectedReturn(IConventionStoredProcedure sproc)\n{\n    if (sproc.FindRowsAffectedParameter() is not null\n        || sproc.FindRowsAffectedResultColumn() is not null)\n    {\n        throw new InvalidOperationException(\n            \"Cannot enable return-value rows affected: a parameter or result column already exists.\");\n    }\n    sproc.SetIsRowsAffectedReturned(true);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide rows-affected mechanism (return value / output param / result column) once per sproc.","Centralize sproc configuration in one builder method to avoid stacking mechanisms."],"tags":["relational","stored-procedure","rows-affected","configuration"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}