{"record":{"id":"0af3b073fd7f77d2","repo":"dotnet/efcore","slug":"unhandled-expression-expression-of-type-expr-0af3b0","errorCode":null,"errorMessage":"Unhandled expression '{expression}' of type '{expressionType}' encountered in '{visitor}'.","messagePattern":"Unhandled expression '(.+?)' of type '(.+?)' encountered in '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/QuerySqlGenerator.cs","lineNumber":157,"sourceCode":"            RightJoinExpression e => VisitRightJoin(e),\n            FullJoinExpression e => VisitFullJoin(e),\n            RowNumberExpression e => VisitRowNumber(e),\n            RowValueExpression e => VisitRowValue(e),\n            ScalarSubqueryExpression e => VisitScalarSubquery(e),\n            SelectExpression e => VisitSelect(e),\n            SqlBinaryExpression e => VisitSqlBinary(e),\n            SqlConstantExpression e => VisitSqlConstant(e),\n            SqlFragmentExpression e => VisitSqlFragment(e),\n            SqlFunctionExpression e => VisitSqlFunction(e),\n            SqlParameterExpression e => VisitSqlParameter(e),\n            SqlUnaryExpression e => VisitSqlUnary(e),\n            TableExpression e => VisitTable(e),\n            UnionExpression e => VisitUnion(e),\n            UpdateExpression e => VisitUpdate(e),\n            JsonScalarExpression e => VisitJsonScalar(e),\n            ValuesExpression e => VisitValues(e),\n\n            _ => throw new InvalidOperationException(\n                RelationalStrings.UnhandledExpressionInVisitor(expression, expression.GetType(), nameof(QuerySqlGenerator))),\n        };\n\n    /// <summary>\n    ///     Generates SQL for an arbitrary fragment.\n    /// </summary>\n    /// <param name=\"sqlFragmentExpression\">The <see cref=\"SqlFragmentExpression\" /> for which to generate SQL.</param>\n    protected virtual Expression VisitSqlFragment(SqlFragmentExpression sqlFragmentExpression)\n    {\n        _relationalCommandBuilder.Append(sqlFragmentExpression.Sql);\n\n        return sqlFragmentExpression;\n    }\n\n    private static bool TryUnwrapBareSetOperation(SelectExpression selectExpression, [NotNullWhen(true)] out SetOperationBase? setOperation)\n    {\n        if (selectExpression is\n            {","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/QuerySqlGenerator.cs#L139-L175","documentation":"Thrown by QuerySqlGenerator's main expression switch (the default case) when it encounters a SQL expression type it does not have a Visit method for. The QuerySqlGenerator handles known SqlExpression subtypes (SqlBinaryExpression, SqlConstantExpression, etc.); any unrecognized Expression falls through to this throw. This is almost always a provider bug — the translator declared an expression as supported but the SQL generator can't emit it.","triggerScenarios":"A custom EF Core provider (or an internal EF Core relational pipeline path) produces a SqlExpression-derived type that the QuerySqlGenerator's switch doesn't handle. The expression passed translation but fails at SQL generation time because no VisitXxx method exists for it.","commonSituations":"Third-party database provider that has incomplete SQL generation coverage. EF Core internal bug where a new SqlExpression type was added to translation but not to the generator. Using a preview or nightly EF Core build with incomplete feature implementation.","solutions":["If using a third-party provider, report the issue to the provider maintainer with the expression type from the error message.","If using EF Core directly, file an issue at https://github.com/dotnet/efcore with the query and full exception details.","Try reformulating the query to avoid the expression pattern that triggers the unhandled type."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var result = await query.ToListAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unhandled expression\"))\n{\n    logger.LogError(ex, \"SQL generator encountered unhandled expression type — possible provider bug\");\n    // Try reformulating the query to avoid the unsupported expression pattern\n    throw;\n}","preventionTips":["Keep queries within the set of patterns documented as supported by your provider.","Report unhandled expression errors to the provider maintainer with the query and stack trace.","Avoid using preview or nightly EF Core builds in production."],"tags":["sql-generation","expression-tree","provider-bug","internal-error"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}