dotnet/efcore · error · NotSupportedException
LINQ query comprehension syntax is currently not supported…
Error message
LINQ query comprehension syntax is currently not supported in precompiled queries.
What it means
Thrown as NotSupportedException when the translator encounters a LINQ query comprehension expression (from ... where ... select ... syntax, also known as query syntax or query comprehension syntax). EF Core's precompiled query translator only supports method-syntax LINQ (lambda-based calls like .Where(), .Select(), .OrderBy()). Query comprehension syntax is a well-known design limitation called out explicitly via the localized resource string QueryComprehensionSyntaxNotSupportedInPrecompiledQueries.
Solutions
- Rewrite the query from comprehension syntax to method syntax: convert `from x in source where pred select proj` to `source.Where(x => pred).Select(x => proj)`.
- Use an IDE refactoring or Roslyn analyzer to auto-convert query syntax to method syntax before enabling precompilation.
- For complex multi-clause queries (joins, groupings, let clauses), convert each clause to its method equivalent: Join, GroupJoin, GroupBy, SelectMany, etc.
- If rewriting is not feasible, exclude that specific query from precompilation and let it compile at runtime as before.
- Note: QueryLocator.cs also surfaces this same error at a higher level — both paths produce the same message.
Example fix
// before — query comprehension syntax
var query = from b in ctx.Blogs
where b.Active
select b.Name;
// after — method syntax
var query = ctx.Blogs
.Where(b => b.Active)
.Select(b => b.Name); Defensive patterns
Strategy: validation
Validate before calling
// Before precompiling, scan for LINQ query comprehension syntax
var queryExpressions = querySyntaxTree.DescendantNodes()
.OfType<QueryExpressionSyntax>();
if (queryExpressions.Any())
ReportError("LINQ query comprehension syntax is not supported in precompiled queries — convert to method syntax");
// Also check for query-expression clauses that trigger the QueryLocator path
var queryContinuations = querySyntaxTree.DescendantNodes()
.OfType<QueryBodySyntax>();
if (queryContinuations.Any())
ReportError("Query body clauses (where/select/join/etc.) must be rewritten as method calls"); Prevention
- Write all precompiled queries in method syntax (.Where(), .Select(), .OrderBy(), .Join(), etc.) from the start.
- Enable a Roslyn analyzer that flags query comprehension syntax in files marked for precompilation.
- Convert existing queries using IDE refactoring before enabling precompilation.
- Document the method-syntax requirement in team coding standards for precompiled query files.
- For joins and groupings, learn the method equivalents: Join(), GroupJoin(), GroupBy(), SelectMany().
When it happens
Trigger: A precompiled query is written using C# LINQ query comprehension syntax: `from b in ctx.Blogs where b.Active select b.Name`. The translator's VisitQueryExpression override unconditionally throws NotSupportedException because translating query-syntax ASTs into method-call expression trees requires a full query-syntax-to-method-syntax rewriting pass that is not implemented.
Common situations: Developers who prefer SQL-like query syntax in their LINQ queries (common in teams with SQL backgrounds); legacy query code that was written in query syntax and is now being adopted into precompiled queries; queries ported from examples/tutorials that use query syntax; large existing codebases where rewriting all queries to method syntax is impractical.
Related errors
- Lambda with null expression body
- ArrayCreation: multi-dimensional array
- Could not find symbol for method invocation
- Could not find symbol for typeof() expression
- Couldn't find single Add method on type
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/94fca48f1937cb41.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:990
SyntaxKind.PostDecrementExpression => throw NotSupportedInExpressionTrees(),
_ => throw new UnreachableException(
$"Unexpected syntax kind '{unary.Kind()}' when visiting a {nameof(PostfixUnaryExpressionSyntax)}")
};
NotSupportedException NotSupportedInExpressionTrees()
=> throw new UnreachableException(
$"Unary expression of type {unary.Kind()} is not supported in expression trees");
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Expression VisitQueryExpression(QueryExpressionSyntax node)
=> throw new NotSupportedException(DesignStrings.QueryComprehensionSyntaxNotSupportedInPrecompiledQueries);
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Expression VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax lambda)
=> VisitLambdaExpression(lambda);
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Expression VisitTypeOfExpression(TypeOfExpressionSyntax typeOf)
{View on GitHub (pinned to 3a2006ef56)