{"record":{"id":"7a222499cbdcdb00","repo":"dotnet/efcore","slug":"facet-cannot-be-configured-for-the-parameter","errorCode":null,"errorMessage":"'{facet}' cannot be configured for the parameter '{parameter}' of the stored procedure '{sproc}'.","messagePattern":"'(.+?)' cannot be configured for the parameter '(.+?)' of the stored procedure '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/StoredProcedureParameter.cs","lineNumber":207,"sourceCode":"    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual ParameterDirection Direction\n    {\n        get => _direction ?? ParameterDirection.Input;\n        set => SetDirection(value, ConfigurationSource.Explicit);\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 ParameterDirection SetDirection(ParameterDirection direction, ConfigurationSource configurationSource)\n    {\n        if (ForRowsAffected)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.StoredProcedureParameterInvalidConfiguration(\n                    nameof(Direction), Name, ((IReadOnlyStoredProcedure)StoredProcedure).GetStoreIdentifier()?.DisplayName()));\n        }\n\n        if (!IsValid(direction))\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.StoredProcedureParameterInvalidDirection(\n                    direction, Name, ((IReadOnlyStoredProcedure)StoredProcedure).GetStoreIdentifier()?.DisplayName()));\n        }\n\n        _direction = direction;\n\n        _directionConfigurationSource = configurationSource.Max(_directionConfigurationSource);\n\n        return direction;\n    }\n","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/StoredProcedureParameter.cs#L189-L225","documentation":"The Direction facet cannot be configured on a parameter that exists solely to carry the rows-affected count. Rows-affected parameters have a fixed direction dictated by the provider, so SetDirection rejects the call outright via the ForRowsAffected guard.","triggerScenarios":"Calling .HasDirection(...) or setting Direction on a StoredProcedureParameter whose ForRowsAffected is true (created by RowsAffectedParameter()).","commonSituations":"Treating a rows-affected parameter like a normal output parameter and adding .HasDirection(Output); applying a generic parameter-configuration loop that sets direction on every parameter including rows-affected ones.","solutions":["Skip direction configuration for rows-affected parameters; EF sets it implicitly.","Branch on parameter.ForRowsAffected before calling HasDirection.","If you need a real output parameter, map it via a normal parameter, not RowsAffectedParameter().","Audit generic fluent helpers to exclude rows-affected/result columns from per-parameter configuration."],"exampleFix":"// before\nforeach (var p in sp.Parameters)\n{\n    p.HasDirection(ParameterDirection.Output); // throws on rows-affected\n}\n\n// after\nforeach (var p in sp.Parameters)\n{\n    if (!p.ForRowsAffected)\n    {\n        p.HasDirection(ParameterDirection.Output);\n    }\n}","handlingStrategy":"validation","validationCode":"foreach (var p in sp.Parameters)\n{\n    if (!p.ForRowsAffected)\n    {\n        p.HasDirection(direction);\n    }\n}","typeGuard":"static bool CanConfigureDirection(StoredProcedureParameter p)\n    => !p.ForRowsAffected;","tryCatchPattern":null,"preventionTips":["Exclude rows-affected parameters from generic per-parameter configuration loops.","Document that rows-affected parameters have a provider-fixed direction.","Keep a single helper that configures only regular parameters."],"tags":["ef-core","stored-procedure","configuration","parameter-direction","rows-affected"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}