dotnet/efcore · error · NotSupportedException
LINQ query comprehension syntax is currently not supported i
Error message
LINQ query comprehension syntax is currently not supported in precompiled queries.
What it means
VisitQueryExpression throws NotSupportedException for C# LINQ query comprehension syntax (from ... where ... select). Precompiled queries only support the method-based LINQ syntax that maps to expression-tree-building extension methods; query comprehension is an explicit, documented limitation.
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 dbf9771522)
Solutions
- Rewrite the query using method syntax with lambda expressions
- Convert each clause: from/where -> .Where, orderby -> .OrderBy, select -> .Select
Example fix
// before from b in ctx.Blogs where b.Active select b // after ctx.Blogs.Where(b => b.Active)
Defensive patterns
Strategy: validation
Validate before calling
// Detect query comprehension syntax in precompiled query source.
static bool UsesQuerySyntax(string src)
=> System.Text.RegularExpressions.Regex.IsMatch(src, @"\b(from|select|orderby|group\s+by|join)\b");
if (UsesQuerySyntax(querySource)) { /* rewrite to method syntax */ } Prevention
- Always write precompiled queries in method syntax (.Where/.Select/.OrderBy)
- Convert query-syntax examples before pasting them into a precompiled query
- Enable an analyzer/roslynator rule to flag query syntax in precompiled query files
When it happens
Trigger: Writing a precompiled query using SQL-like query syntax: from b in ctx.Blogs where b.Active orderby b.Name select b.
Common situations: Developers who prefer SQL-like LINQ syntax or paste query-syntax examples into a precompiled query.
Related errors
- ArrayCreation: non-array type symbol: {implicitArrayCreation
- ArrayCreation: multi-dimensional array: {implicitArrayCreati
- Could not find symbol for method invocation: {invocation}
- Invocation over non-member access: {invocation}
- Invocation: couldn't find method '{methodSymbol.Name}' on ty
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/94fca48f1937cb41.
Report an issue: GitHub.