{"record":{"id":"aae4ba30806e6047","repo":"dotnet/efcore","slug":"only-one-ordering-using-scoring-function-is-allowe","errorCode":null,"errorMessage":"Only one ordering using scoring function is allowed. Use 'EF.Functions.{rrf}' method to combine multiple scoring functions.","messagePattern":"Only one ordering using scoring function is allowed\\. Use 'EF\\.Functions\\.(.+?)' method to combine multiple scoring functions\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/Expressions/SelectExpression.cs","lineNumber":484,"sourceCode":"        _orderings.Clear();\n        _orderings.Add(orderingExpression);\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 void AppendOrdering(OrderingExpression orderingExpression)\n    {\n        if (_orderings.Count > 0)\n        {\n            var existingScoringFunctionOrdering = _orderings is [{ Expression: SqlFunctionExpression { IsScoringFunction: true } }];\n            var appendingScoringFunctionOrdering = orderingExpression.Expression is SqlFunctionExpression { IsScoringFunction: true };\n            if (appendingScoringFunctionOrdering || existingScoringFunctionOrdering)\n            {\n                throw new InvalidOperationException(\n                    appendingScoringFunctionOrdering && existingScoringFunctionOrdering\n                        ? CosmosStrings.OrderByMultipleScoringFunctionWithoutRrf(nameof(CosmosDbFunctionsExtensions.Rrf))\n                        : CosmosStrings.OrderByScoringFunctionMixedWithRegularOrderby);\n            }\n        }\n\n        if (_orderings.FirstOrDefault(o => o.Expression.Equals(orderingExpression.Expression)) == null)\n        {\n            _orderings.Add(orderingExpression);\n        }\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>","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Query/Internal/Expressions/SelectExpression.cs#L466-L502","documentation":"SelectExpression.AppendOrdering throws InvalidOperationException when you attempt to add a second scoring-function ordering. Only one scoring ordering is permitted per query; multiple scoring functions must be fused via EF.Functions.Rrf (Reciprocal Rank Fusion), which produces a single combined scoring expression.","triggerScenarios":"Chaining two OrderBy/ThenBy calls each using a scoring function: `.OrderBy(a => EF.Functions.FullTextScore(a.F1, \"x\")).OrderBy(a => EF.Functions.FullTextScore(a.F2, \"y\"))`.","commonSituations":"Wanting to weight several full-text matches independently; assuming Cosmos accepts multiple ORDER BY scoring clauses.","solutions":["Combine the scoring functions into one RRF call and order by that: `OrderBy(a => EF.Functions.Rrf(score1, score2, ...))`.","If fusing is not desired, pick the single most relevant scoring function and drop the others.","Apply secondary ordering on a non-scoring expression only if it does not mix with scoring (see related error 108)."],"exampleFix":"// before\nvar q = ctx.Articles\n    .OrderBy(a => EF.Functions.FullTextScore(a.Title, \"x\"))\n    .OrderBy(a => EF.Functions.FullTextScore(a.Body, \"y\"));\n\n// after\nvar q = ctx.Articles\n    .OrderBy(a => EF.Functions.Rrf(\n        EF.Functions.FullTextScore(a.Title, \"x\"),\n        EF.Functions.FullTextScore(a.Body, \"y\")));","handlingStrategy":"validation","validationCode":"// Static analysis helper: count scoring orderings in the query before executing.\n// Ensure at most one; fuse extras via EF.Functions.Rrf.","typeGuard":null,"tryCatchPattern":"try { var q = query.ToList(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Rrf\"))\n{ /* combine scoring functions with EF.Functions.Rrf into one OrderBy */ }","preventionTips":["Fuse multiple scoring functions via EF.Functions.Rrf before ordering.","Keep exactly one scoring OrderBy per query."],"tags":["cosmos","full-text-search","ordering","scoring-function","rrf"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}