{"record":{"id":"59441af89c3534a5","repo":"dotnet/efcore","slug":"unhandled-expression-expression-of-type-expr","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.Cosmos/Query/Internal/CosmosQuerySqlGenerator.cs","lineNumber":97,"sourceCode":"            ObjectFunctionExpression e => VisitObjectFunction(e),\n            ObjectReferenceExpression e => VisitObjectReference(e),\n            OrderingExpression e => VisitOrdering(e),\n            ProjectionExpression e => VisitProjection(e),\n            ScalarAccessExpression e => VisitScalarAccess(e),\n            ScalarArrayExpression e => VisitScalarArray(e),\n            ScalarReferenceExpression e => VisitValueReference(e),\n            ScalarSubqueryExpression e => VisitScalarSubquery(e),\n            SelectExpression e => VisitSelect(e),\n            SourceExpression e => VisitSource(e),\n            SqlBinaryExpression e => VisitSqlBinary(e),\n            SqlConditionalExpression e => VisitSqlConditional(e),\n            SqlConstantExpression e => VisitSqlConstant(e),\n            SqlFunctionExpression e => VisitSqlFunction(e),\n            SqlParameterExpression e => VisitSqlParameter(e),\n            SqlUnaryExpression e => VisitSqlUnary(e),\n            StructuralTypeProjectionExpression e => VisitStructuralTypeProjection(e),\n\n            _ => throw new InvalidOperationException(\n                CosmosStrings.UnhandledExpressionInVisitor(expression, expression.GetType(), nameof(CosmosQuerySqlGenerator))),\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    protected virtual Expression VisitStructuralTypeProjection(StructuralTypeProjectionExpression structuralTypeProjectionExpression)\n    {\n        Visit(structuralTypeProjectionExpression.Object);\n\n        return structuralTypeProjectionExpression;\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Query/Internal/CosmosQuerySqlGenerator.cs#L79-L115","documentation":"Thrown by CosmosQuerySqlGenerator when its expression switch hits the default arm: the expression node type is not one of the recognized SQL node kinds (ObjectReferenceExpression, OrderingExpression, ProjectionExpression, ScalarAccess/Array/Reference/Subquery, SelectExpression, SourceExpression, SqlBinary/Conditional/Constant/Function/Parameter/Unary, StructuralTypeProjectionExpression). This indicates an internally-malformed query tree reached the SQL emitter and is almost always an EF Core infrastructure bug rather than a user LINQ mistake.","triggerScenarios":"An expression of a type not in the generator's switch arms reaches Visit; typically produced by another visitor producing a non-Cosmos SqlExpression node. Can be triggered by certain unsupported query shapes that the translator partially handled then passed an unknown node downstream.","commonSituations":"Provider version mismatch (mixing EF Core runtime version with an older Cosmos provider). Edge-case queries (specific operators, JSON helpers) where the translator emits a node the generator cannot render. Usually not reproducible by simple LINQ.","solutions":["Simplify the query to isolate which operator introduces the unsupported node, then evaluate that part client-side.","Update the Microsoft.EntityFrameworkCore.Cosmos package to exactly match the EF Core runtime version in use.","If the query is minimal and still throws, capture the expressionType from the message and file an EF Core issue; it is a provider gap."],"exampleFix":"// before\nvar q = db.Items\n    .Where(i => SomeUnsupportedOperator(i.Data))\n    .ToList();\n\n// after\nvar all = await db.Items.ToListAsync();\nvar q = all.Where(i => SomeUnsupportedOperator(i.Data)).ToList();","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    return await query.ToListAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unhandled expression\"))\n{\n    // Capture expressionType from the message, simplify the query, or materialize client-side\n    var all = await db.Set<TEntity>().ToListAsync();\n    return /* client-side filter/transformation */;\n}","preventionTips":["Pin the Microsoft.EntityFrameworkCore.Cosmos package version to exactly match the EF Core runtime.","Minimize exotic query shapes (raw SQL composed with LINQ, unusual operators) on Cosmos; isolate them in tests."],"tags":["cosmos","ef-core","query","sql-generation","provider"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}