{"record":{"id":"81de7d2340252e6c","repo":"dotnet/efcore","slug":"the-methodname-method-is-not-supported-because","errorCode":null,"errorMessage":"The '{methodName}' method is not supported because the query has switched to client-evaluation. This usually happens when the arguments to the method cannot be translated to server. Rewrite the query to avoid client evaluation of arguments so that method can be translated to server.","messagePattern":"The '(.+?)' method is not supported because the query has switched to client-evaluation\\. This usually happens when the arguments to the method cannot be translated to server\\. Rewrite the query to avoid client evaluation of arguments so that method can be translated to server\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Extensions/CosmosDbFunctionsExtensions.cs","lineNumber":28,"sourceCode":"/// <remarks>\n///     See <see href=\"https://aka.ms/efcore-docs-database-functions\">Database functions</see>, and\n///     <see href=\"https://aka.ms/efcore-docs-cosmos\">Accessing Cosmos with EF Core</see> for more information and examples.\n/// </remarks>\npublic static class CosmosDbFunctionsExtensions\n{\n    /// <summary>\n    ///     Returns a boolean indicating if the property has been assigned a value. Corresponds to the Cosmos <c>IS_DEFINED</c> function.\n    /// </summary>\n    /// <remarks>\n    ///     See <see href=\"https://aka.ms/efcore-docs-database-functions\">Database functions</see>, and\n    ///     <see href=\"https://aka.ms/efcore-docs-cosmos\">Accessing Cosmos with EF Core</see>\n    ///     for more information and examples.\n    /// </remarks>\n    /// <param name=\"_\">The <see cref=\"DbFunctions\" /> instance.</param>\n    /// <param name=\"expression\">The expression to check.</param>\n    /// <seealso href=\"https://learn.microsoft.com/azure/cosmos-db/nosql/query/is-defined\">Cosmos <c>IS_DEFINED_</c> function</seealso>\n    public static bool IsDefined(this DbFunctions _, object? expression)\n        => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(IsDefined)));\n\n    /// <summary>\n    ///     Coalesces a Cosmos <c>undefined</c> value via the <c>??</c> operator.\n    /// </summary>\n    /// <remarks>\n    ///     See <see href=\"https://aka.ms/efcore-docs-database-functions\">Database functions</see>, and\n    ///     <see href=\"https://aka.ms/efcore-docs-cosmos\">Accessing Cosmos with EF Core</see>\n    ///     for more information and examples.\n    /// </remarks>\n    /// <param name=\"_\">The <see cref=\"DbFunctions\" /> instance.</param>\n    /// <param name=\"expression1\">\n    ///     The expression to coalesce. This expression will be returned unless it is <c>undefined</c>, in which case\n    ///     <paramref name=\"expression2\" /> will be returned.\n    /// </param>\n    /// <param name=\"expression2\">The expression to be returned if <paramref name=\"expression1\" /> is <c>undefined</c>.</param>\n    /// <seealso href=\"https://learn.microsoft.com/azure/cosmos-db/nosql/query/ternary-coalesce-operators#coalesce-operator\">\n    ///     Cosmos coalesce operator\n    /// </seealso>","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Extensions/CosmosDbFunctionsExtensions.cs#L10-L46","documentation":"CosmosDbFunctionsExtensions.IsDefined is a translation-only stub — its method body unconditionally throws InvalidOperationException(CoreStrings.FunctionOnClient). It exists solely so that EF Core's LINQ provider can recognize and translate the call into the Cosmos IS_DEFINED SQL function when used inside an IQueryable query. Calling it directly (outside a translatable LINQ expression) always throws because there is no client-side implementation.","triggerScenarios":"Calling EF.Functions.IsDefined(someValue) outside of a LINQ query, e.g., in a regular method body, a loop, or passing the result to a non-query variable. The throw fires immediately because the expression engine never intercepts the call. Also triggered when arguments to the method cannot be translated, forcing client evaluation.","commonSituations":"Accidentally invoking EF.Functions.IsDefined in imperative code rather than in a Where/Select clause; using it inside a query that partially falls back to client evaluation due to untranslatable arguments; testing EF.Functions methods in unit tests without a real IQueryable provider.","solutions":["Use EF.Functions.IsDefined only inside IQueryable LINQ expressions (e.g., Where(x => EF.Functions.IsDefined(x.OptionalField))).","If the query fell back to client evaluation, rewrite it so all arguments to IsDefined are translatable (entity properties, constants, parameters — not local method calls).","For checking nullability in client-side logic, use a regular null check or HasValue instead of EF.Functions.IsDefined."],"exampleFix":"// before — called outside LINQ query\nvar exists = EF.Functions.IsDefined(myObject.Field); // throws\n\n// after — used inside translatable LINQ query\nvar results = await context.Items\n    .Where(x => EF.Functions.IsDefined(x.OptionalField))\n    .ToListAsync();","handlingStrategy":"validation","validationCode":"// Ensure EF.Functions.IsDefined is only used in IQueryable expressions\n// This is a design-time check, not runtime validation:\n// CORRECT usage:\nvar query = context.Items.Where(x => EF.Functions.IsDefined(x.OptionalField));\n// INCORRECT (will throw): var result = EF.Functions.IsDefined(someValue);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call EF.Functions.IsDefined directly in imperative code.","Use it only inside Where, Select, or other IQueryable LINQ clauses against a Cosmos DbContext.","If you need a null-check in client code, use a regular != null or HasValue check instead."],"tags":["ef-core","cosmos","linq-translation","db-functions","client-evaluation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}