dotnet/efcore · error · InvalidOperationException
The '{methodName}' method is not supported because the query
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
EF.Functions.Collate is a query-only method whose body throws InvalidOperationException(CoreStrings.FunctionOnClient) if it is ever executed on the client. EF is supposed to translate it to a SQL COLLATE clause; the throw fires only when translation fails and EF evaluates the expression client-side.
Source
Thrown at src/EFCore.Relational/Extensions/RelationalDbFunctionsExtensions.cs:35
/// <summary>
/// Explicitly specifies a collation to be used in a LINQ query. Can be used to generate fragments such as
/// <c>WHERE customer.name COLLATE 'de_DE' = 'John Doe'</c>.
/// </summary>
/// <remarks>
/// <para>
/// The available collations and their names vary across databases, consult your database's documentation for more
/// information.
/// </para>
/// <para>
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see> for more information and examples.
/// </para>
/// </remarks>
/// <typeparam name="TProperty">The type of the operand on which the collation is being specified.</typeparam>
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
/// <param name="operand">The operand to which to apply the collation.</param>
/// <param name="collation">The name of the collation.</param>
public static TProperty Collate<TProperty>(this DbFunctions _, TProperty operand, [NotParameterized] string collation)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Collate)));
/// <summary>
/// Returns the smallest value from the given list of values. Usually corresponds to the <c>LEAST</c> SQL function.
/// </summary>
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
/// <param name="values">The list of values from which return the smallest value.</param>
public static T Least<T>(this DbFunctions _, [NotParameterized] params T[] values)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Least)));
/// <summary>
/// Returns the greatest value from the given list of values. Usually corresponds to the <c>GREATEST</c> SQL function.
/// </summary>
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
/// <param name="values">The list of values from which return the greatest value.</param>
public static T Greatest<T>(this DbFunctions _, [NotParameterized] params T[] values)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Greatest)));
/// <summary>View on GitHub (pinned to dbf9771522)
Solutions
- Apply Collate directly to an entity property inside the translated query: ctx.Users.Where(u => EF.Functions.Collate(u.Name, "de_DE") == input).
- Remove client-side wrappers around the operand so the whole predicate is server-translatable.
- Ensure the call is before any AsEnumerable()/ToList() that switches to client evaluation.
- If the collation must be applied client-side, do the comparison in .NET instead of via Collate.
Example fix
// before
var names = GetNames();
var q = ctx.Users.Where(u => names.Contains(EF.Functions.Collate(u.Name, "de_DE")));
// un-translatable -> client eval -> throws
// after
var q = ctx.Users
.Where(u => EF.Functions.Collate(u.Name, "de_DE") == input);
// or pre-filter client values, keep Collate on the property only Defensive patterns
Strategy: validation
Validate before calling
// Ensure Collate is only used inside the translated query on a property
var q = ctx.Users
.Where(u => EF.Functions.Collate(u.Name, "de_DE") == input); Prevention
- Apply Collate to entity properties, not client values.
- Keep Collate before any AsEnumerable/ToList boundary.
- Confirm the provider translates collation for that expression shape.
When it happens
Trigger: Using EF.Functions.Collate(operand, collation) in a query where the operand or surrounding expression cannot be translated, causing client evaluation (RelationalDbFunctionsExtensions.cs:34-35). Also if invoked outside a query entirely.
Common situations: Collate applied to a client-computed value rather than an entity property; wrapped in an un-translatable method; used after AsEnumerable; provider that lacks collation translation; collation name built dynamically in a non-translatable way.
Related errors
- The 'EF.MultipleParameters<T>' method may only be used withi
- TranslationFailed
- TranslationFailedWithDetails
- The '{methodName}' method is not supported because the query
- LINQ query comprehension syntax is currently not supported i
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/110f4f17890b553c.
Report an issue: GitHub.