{"record":{"id":"94fca48f1937cb41","repo":"dotnet/efcore","slug":"linq-query-comprehension-syntax-is-currently-not-s","errorCode":null,"errorMessage":"LINQ query comprehension syntax is currently not supported in precompiled queries.","messagePattern":"LINQ query comprehension syntax is currently not supported in precompiled queries\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":990,"sourceCode":"            SyntaxKind.PostDecrementExpression => throw NotSupportedInExpressionTrees(),\n\n            _ => throw new UnreachableException(\n                $\"Unexpected syntax kind '{unary.Kind()}' when visiting a {nameof(PostfixUnaryExpressionSyntax)}\")\n        };\n\n        NotSupportedException NotSupportedInExpressionTrees()\n            => throw new UnreachableException(\n                $\"Unary expression of type {unary.Kind()} is not supported in expression trees\");\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override Expression VisitQueryExpression(QueryExpressionSyntax node)\n        => throw new NotSupportedException(DesignStrings.QueryComprehensionSyntaxNotSupportedInPrecompiledQueries);\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override Expression VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax lambda)\n        => VisitLambdaExpression(lambda);\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override Expression VisitTypeOfExpression(TypeOfExpressionSyntax typeOf)\n    {","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L972-L1008","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — query comprehension syntax\nvar query = from b in ctx.Blogs\n            where b.Active\n            select b.Name;\n\n// after — method syntax\nvar query = ctx.Blogs\n    .Where(b => b.Active)\n    .Select(b => b.Name);","handlingStrategy":"validation","validationCode":"// Before precompiling, scan for LINQ query comprehension syntax\nvar queryExpressions = querySyntaxTree.DescendantNodes()\n    .OfType<QueryExpressionSyntax>();\nif (queryExpressions.Any())\n    ReportError(\"LINQ query comprehension syntax is not supported in precompiled queries — convert to method syntax\");\n\n// Also check for query-expression clauses that trigger the QueryLocator path\nvar queryContinuations = querySyntaxTree.DescendantNodes()\n    .OfType<QueryBodySyntax>();\nif (queryContinuations.Any())\n    ReportError(\"Query body clauses (where/select/join/etc.) must be rewritten as method calls\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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()."],"tags":["precompiled-queries","roslyn","linq","query-syntax","not-supported","expression-tree"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}