dotnet/efcore · error · InvalidOperationException
The LINQ expression ' ' could not be translated. Either…
Error message
The LINQ expression '{expression}' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information. What it means
Thrown by the relational projection binding visitor when it encounters a ParameterExpression that cannot be translated to SQL while performing index-based projection binding. This means a LINQ projection referenced a parameter (like a closure variable or an unbound parameter expression) that EF Core's query translator could not map to a SQL expression, and it falls through to client evaluation which is disabled by default.
Solutions
- Rewrite the projection to only use translatable operations — move non-translatable logic after AsEnumerable() so it runs client-side.
- Split the query: use Select() with only server-side fields, call ToList()/AsEnumerable(), then project further client-side.
- If referencing a parameterized value, ensure it's passed as a query parameter (variable in an interpolated lambda) not as an expression parameter.
- Check the EF Core docs for supported translations of the specific pattern you're using.
Example fix
// before
var result = context.Blogs
.Select(b => new { Title = b.Title, Formatted = FormatBlog(b) }) // FormatBlog is untranslatable
.ToList();
// after
var result = context.Blogs
.Select(b => new { b.Title, b.Content })
.AsEnumerable()
.Select(b => new { b.Title, Formatted = FormatBlog(b) })
.ToList(); Defensive patterns
Strategy: try-catch
Try / catch
try
{
var result = await context.Blogs
.Select(b => new { b.Title, Computed = SomeUntranslatableCall(b) })
.ToListAsync();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("could not be translated"))
{
// Fallback: split into server-side + client-side projection
var raw = await context.Blogs.Select(b => new { b.Title, b.Content }).ToListAsync();
var result = raw.Select(b => new { b.Title, Computed = SomeUntranslatableCall(b) }).ToList();
} Prevention
- Keep server-side projections simple — only map properties and basic expressions EF can translate.
- Move non-translatable logic after AsEnumerable() or ToListAsync().
- Review the EF Core supported query patterns documentation for your provider.
- Write integration tests for complex queries to catch translation failures early.
When it happens
Trigger: Writing a LINQ Select() projection that references a ParameterExpression directly — typically an untranslatable lambda parameter, an external closure variable used inside a projection in a way the translator can't inline, or a custom expression tree node that reduces to a bare ParameterExpression.
Common situations: Using a method call inside Select() that EF cannot translate (e.g., calling a custom method, using ToString with format strings on unsupported providers). Referencing a local variable in a way that creates an unbound parameter. Using complex projections with conditional logic that the translator can't handle. Provider-specific limitation (e.g., SQLite not supporting a SQL Server function).
Related errors
- The ' ' method is not supported because the query has…
- Complex projections in subqueries are currently unsupported.
- Invalid token type: ' '.
- The 'EF.MultipleParameters
- The LINQ expression ' ' could not be translated. Either…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/d302b7a23ec66bf7.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs:131
case null:
return null;
case not null when _indexBasedBinding:
{
switch (expression)
{
case ConstantExpression:
return expression;
case QueryParameterExpression queryParameterExpression:
return Expression.Call(
GetParameterValueMethodInfo.MakeGenericMethod(queryParameterExpression.Type),
QueryCompilationContext.QueryContextParameter,
Expression.Constant(queryParameterExpression.Name));
case ParameterExpression parameterExpression:
throw new InvalidOperationException(CoreStrings.TranslationFailed(parameterExpression.Print()));
case ProjectionBindingExpression projectionBindingExpression:
return _selectExpression.GetProjection(projectionBindingExpression) switch
{
StructuralTypeProjectionExpression projection => AddClientProjection(projection, typeof(ValueBuffer)),
SqlExpression mappedSqlExpression => AddClientProjection(mappedSqlExpression, expression.Type.MakeNullable()),
// A single-result subquery (e.g. the group element of GroupBy(k).Select(g => g.First()))
// being composed over: lower it into the current select as a to-one join so the result
// has a bindable shape, instead of failing.
ShapedQueryExpression
{
ResultCardinality: ResultCardinality.Single or ResultCardinality.SingleOrDefault
} singleResultSubquery
=> LowerSingleResultSubquery(projectionBindingExpression, singleResultSubquery),
_ => throw new InvalidOperationException(CoreStrings.TranslationFailed(projectionBindingExpression.Print()))
};
case MaterializeCollectionNavigationExpression materializeCollectionNavigationExpression:View on GitHub (pinned to 3a2006ef56)