dotnet/efcore · error · InvalidOperationException
The ' ' method is not supported because the query has…
Error message
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. What it means
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.
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.
Example fix
// before — called outside LINQ query
var exists = EF.Functions.IsDefined(myObject.Field); // throws
// after — used inside translatable LINQ query
var results = await context.Items
.Where(x => EF.Functions.IsDefined(x.OptionalField))
.ToListAsync(); Defensive patterns
Strategy: validation
Validate before calling
// Ensure EF.Functions.IsDefined is only used in IQueryable expressions // This is a design-time check, not runtime validation: // CORRECT usage: var query = context.Items.Where(x => EF.Functions.IsDefined(x.OptionalField)); // INCORRECT (will throw): var result = EF.Functions.IsDefined(someValue);
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- An Azure Cosmos DB container name is defined on entity type
- Cosmos-specific methods can only be used when the context…
- Specified argument was out of the range of valid values…
- The discriminator value for
- The 'EF.MultipleParameters
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/81de7d2340252e6c.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Cosmos/Extensions/CosmosDbFunctionsExtensions.cs:28
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Cosmos with EF Core</see> for more information and examples.
/// </remarks>
public static class CosmosDbFunctionsExtensions
{
/// <summary>
/// Returns a boolean indicating if the property has been assigned a value. Corresponds to the Cosmos <c>IS_DEFINED</c> function.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Cosmos with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
/// <param name="expression">The expression to check.</param>
/// <seealso href="https://learn.microsoft.com/azure/cosmos-db/nosql/query/is-defined">Cosmos <c>IS_DEFINED_</c> function</seealso>
public static bool IsDefined(this DbFunctions _, object? expression)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(IsDefined)));
/// <summary>
/// Coalesces a Cosmos <c>undefined</c> value via the <c>??</c> operator.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Cosmos with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
/// <param name="expression1">
/// The expression to coalesce. This expression will be returned unless it is <c>undefined</c>, in which case
/// <paramref name="expression2" /> will be returned.
/// </param>
/// <param name="expression2">The expression to be returned if <paramref name="expression1" /> is <c>undefined</c>.</param>
/// <seealso href="https://learn.microsoft.com/azure/cosmos-db/nosql/query/ternary-coalesce-operators#coalesce-operator">
/// Cosmos coalesce operator
/// </seealso>View on GitHub (pinned to 3a2006ef56)