{"record":{"id":"f9d6b44ff5de897e","repo":"dotnet/efcore","slug":"unsupported-syntax-node-of-type-node-gettype","errorCode":null,"errorMessage":"Unsupported syntax node of type '{node.GetType()}': {node}","messagePattern":"Unsupported syntax node of type '(.+?)': (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":1026,"sourceCode":"    {\n        if (_semanticModel.GetSymbolInfo(typeOf.Type).Symbol is not ITypeSymbol typeSymbol)\n        {\n            throw new InvalidOperationException(\n                \"Could not find symbol for typeof() expression: \" + typeOf);\n        }\n\n        var type = ResolveType(typeSymbol);\n        return Constant(type, typeof(Type));\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 DefaultVisit(SyntaxNode node)\n        => throw new NotSupportedException($\"Unsupported syntax node of type '{node.GetType()}': {node}\");\n\n    private Expression VisitLambdaExpression(AnonymousFunctionExpressionSyntax lambda, Type? expectedType = null)\n    {\n        if (lambda.ExpressionBody is null)\n        {\n            throw new NotSupportedException(\"Lambda with null expression body\");\n        }\n\n        if (lambda.Modifiers.Any())\n        {\n            throw new NotSupportedException(\"Lambda with modifiers not supported: \" + lambda.Modifiers);\n        }\n\n        if (!lambda.AsyncKeyword.IsKind(SyntaxKind.None))\n        {\n            throw new NotSupportedException(\"Async lambdas are not supported\");\n        }\n","sourceCodeStart":1008,"sourceCodeEnd":1044,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L1008-L1044","documentation":"DefaultVisit is the catch-all that throws NotSupportedException for any C# syntax node type lacking a specific Visit* override. It is the generic 'this C# construct is not supported in precompiled queries' error; the node type in the message identifies the offending construct.","triggerScenarios":"Using a C# construct the translator has no visitor for: statement-bodied lambdas, lock/using/checked/unchecked blocks, switch expressions, pattern-matching 'is', tuple expressions, null-conditional ?., query continuations (into), etc.","commonSituations":"Writing modern/advanced C# (pattern matching, switch expressions, null-conditional operators) or statement-style code inside a query that gets precompiled.","solutions":["Identify the unsupported construct from the node type printed in the message","Rewrite using simpler expression-based constructs that map to expression trees","Hoist unsupported logic out of the query into a captured local computed beforehand"],"exampleFix":"// before (switch expression, unsupported)\nvar q = ctx.Items.Select(i => i.Kind switch { 1 => \"a\", _ => \"b\" });\n// after (ternary, supported)\nvar q = ctx.Items.Select(i => i.Kind == 1 ? \"a\" : \"b\");","handlingStrategy":"validation","validationCode":"// Scan precompiled query source for constructs the translator cannot visit.\n// Flag: switch expressions, pattern matching 'is', null-conditional '?.', statement-bodied lambdas,\n// lock/using/checked blocks, tuple expressions.\nstatic bool UsesUnsupported(string src) =>\n    System.Text.RegularExpressions.Regex.IsMatch(src, @\"switch\\s*\\{|\\bis\\s+\\w+\\s+\\w+|\\?\\.|=>\\s*\\{\");\nif (UsesUnsupported(querySource)) { /* rewrite to expression-tree-friendly form */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep precompiled query bodies as simple expression-tree-friendly expressions","Rewrite switch expressions as nested ternaries","Replace null-conditional access with explicit null checks","Hoist complex logic out of the query into captured locals"],"tags":["efcore","precompiled-queries","unsupported-syntax","csharp"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}