{"record":{"id":"61187ff70779a3b6","repo":"dotnet/efcore","slug":"encountered-non-quotable-expression-of-type-node","errorCode":null,"errorMessage":"Encountered non-quotable expression of type {node.GetType()} when translating expression tree to C#","messagePattern":"Encountered non-quotable expression of type (.+?) when translating expression tree to C#","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs","lineNumber":2691,"sourceCode":"\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    protected override Expression VisitExtension(Expression node)\n    {\n        // TODO: Remove any EF-specific code from this visitor (extend if needed)\n        // TODO: Hack mode. Visit the expression beforehand to replace EntityQueryRootExpression with context.Set<>(), or receive it in this visitor as a replacement or something.\n        if (node is EntityQueryRootExpression entityQueryRoot)\n        {\n            // TODO: STET\n            Result = ParseExpression($\"context.Set<{entityQueryRoot.EntityType.ClrType.Name}>()\");\n            return node;\n        }\n\n        throw new NotSupportedException(\n            $\"Encountered non-quotable expression of type {node.GetType()} when translating expression tree to C#\");\n    }\n\n    private ArgumentSyntax[] TranslateMethodArguments(ParameterInfo[] parameters, IReadOnlyList<Expression> arguments)\n    {\n        var translatedExpressions = TranslateList(arguments);\n        var translatedArguments = new ArgumentSyntax[arguments.Count];\n\n        for (var i = 0; i < translatedExpressions.Length; i++)\n        {\n            var parameter = parameters[i];\n            var argument = Argument(translatedExpressions[i]);\n\n            if (parameter.IsOut)\n            {\n                argument = argument.WithRefKindKeyword(Token(SyntaxKind.OutKeyword));\n            }\n            else if (parameter.IsIn)","sourceCodeStart":2673,"sourceCodeEnd":2709,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs#L2673-L2709","documentation":"Thrown by VisitExtension when an extension Expression node is encountered that is not an EntityQueryRootExpression. The translator special-cases EntityQueryRootExpression (rendering it as context.Set<TEntity>()), but any other extension node type is considered non-quotable into C# and throws NotSupportedException with the node's runtime type.","triggerScenarios":"An expression tree passed to the translator contains a custom or EF-internal Expression extension type that is not EntityQueryRootExpression (e.g. a proprietary query root, a specialized EF extension node, or a user-defined Expression subclass).","commonSituations":"A precompiled query references an extension expression the translator has not been taught to handle; mixing in provider-specific extension nodes; upgrading EF where a new internal extension node appears before translator support is added.","solutions":["Remove the unsupported extension node from the query or replace it with a standard expression EF can translate.","If the node is an EF-internal query root, ensure it is an EntityQueryRootExpression so it renders as context.Set<T>().","Report the node type to EF if it appears in a normal query (possible translator gap)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Reject non-EntityQueryRootExpression extension nodes\nstatic bool HasUnknownExtension(Expression e)\n{\n    bool bad = false;\n    new ExtensionChecker { OnBad = () => bad = true }.Visit(e);\n    return bad;\n}\nclass ExtensionChecker : ExpressionVisitor\n{\n    public Action OnBad;\n    protected override Expression VisitExtension(Expression node)\n    {\n        if (node is not EntityQueryRootExpression) OnBad();\n        return base.VisitExtension(node);\n    }\n}","typeGuard":"static bool IsTranslatableExtension(Expression node) => node is EntityQueryRootExpression;","tryCatchPattern":"try { var csharp = translator.Translate(expr); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"non-quotable expression\"))\n{ throw new InvalidOperationException($\"Query contains an extension node type EF cannot translate to C#: {ex.Message}.\", ex); }","preventionTips":["Do not introduce custom Expression subclasses into EF-translated trees.","Ensure query roots are EntityQueryRootExpression.","Report unknown EF-internal extension nodes that appear in normal queries."],"tags":["expression-trees","precompiled-queries","compiled-model","linq","extension-node"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}