{"record":{"id":"738e7247b637bfbc","repo":"dotnet/efcore","slug":"the-parameter-value-passed-to-methodname-m","errorCode":null,"errorMessage":"The '{parameter}' value passed to '{methodName}' must be a constant.","messagePattern":"The '(.+?)' value passed to '(.+?)' must be a constant\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/Translators/CosmosVectorSearchTranslator.cs","lineNumber":45,"sourceCode":"        SqlExpression? instance,\n        MethodInfo method,\n        IReadOnlyList<SqlExpression> arguments,\n        IDiagnosticsLogger<DbLoggerCategory.Query> logger)\n    {\n        if (method.DeclaringType != typeof(CosmosDbFunctionsExtensions)\n            || method.Name != nameof(CosmosDbFunctionsExtensions.VectorDistance))\n        {\n            return null;\n        }\n\n        if (arguments is not [_, var vector1, var vector2, var useBruteForceExpression, var optionsExpression])\n        {\n            throw new UnreachableException();\n        }\n\n        if (useBruteForceExpression is not SqlConstantExpression { Value: var useBruteForceValue })\n        {\n            throw new InvalidOperationException(\n                CoreStrings.ArgumentNotConstant(\"useBruteForce\", nameof(CosmosDbFunctionsExtensions.VectorDistance)));\n        }\n\n        if (optionsExpression is not SqlConstantExpression { Value: var optionsValue })\n        {\n            throw new InvalidOperationException(\n                CoreStrings.ArgumentNotConstant(\"options\", nameof(CosmosDbFunctionsExtensions.VectorDistance)));\n        }\n\n        var options = (VectorDistanceOptions?)optionsValue;\n\n        var vectorMapping = vector1.TypeMapping as CosmosVectorTypeMapping\n            ?? vector2.TypeMapping as CosmosVectorTypeMapping\n            ?? throw new InvalidOperationException(CosmosStrings.VectorSearchRequiresVector);\n\n        var vectorType = vectorMapping.VectorType;\n\n        List<Expression> newArguments =","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Query/Internal/Translators/CosmosVectorSearchTranslator.cs#L27-L63","documentation":"CosmosVectorSearchTranslator throws ArgumentNotConstant when the useBruteForce argument passed to EF.Functions.VectorDistance is not a SqlConstantExpression. Cosmos DB requires this argument to be a literal so it can be inlined into the generated SQL; non-constant values cannot be translated for this parameter.","triggerScenarios":"Passing a variable, parameter, computed value, or column as the useBruteForce argument to VectorDistance(prop, vec, useBruteForce, options).","commonSituations":"Reading the brute-force flag from configuration and passing the variable; passing a method-call result; binding a parameter from a closure.","solutions":["Pass a literal bool (true/false) or null for useBruteForce.","If the value comes from configuration, inline the resolved constant value directly in the expression.","Build separate query branches for the brute-force and non-brute-force cases."],"exampleFix":"// before\nvar brute = settings.UseBruteForce;\nvar q = db.Items.OrderBy(i => EF.Functions.VectorDistance(i.Vec, query, brute, null));\n\n// after - inline the constant\nvar q = db.Items.OrderBy(i => EF.Functions.VectorDistance(i.Vec, query, true, null));","handlingStrategy":"validation","validationCode":"// Only pass compile-time literals for useBruteForce.\nconst bool UseBruteForce = true; // resolved at compile time\nvar q = db.Items.OrderBy(i => EF.Functions.VectorDistance(i.Vec, query, UseBruteForce, null));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass only literal bool or null for useBruteForce.","Branch the query at the call site to inline the resolved constant.","Document that VectorDistance arguments must be compile-time constants for the Cosmos translator."],"tags":["cosmos","vector-search","constant","translation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}