{"record":{"id":"4ac2f9f7b04fb5da","repo":"dotnet/efcore","slug":"unhandled-expression-node-type-nodetype","errorCode":null,"errorMessage":"Unhandled expression node type '{nodeType}'.","messagePattern":"Unhandled expression node type '(.+?)'\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs","lineNumber":62,"sourceCode":"        var (paging, maxItemCount, continuationToken, responseContinuationTokenLimitInKb) =\n            (false, (SqlParameterExpression)null, (SqlParameterExpression)null, (SqlParameterExpression)null);\n\n        // If the query is terminated ToPageAsync(), CosmosQueryableMethodTranslatingExpressionVisitor composed a PagingExpression on top\n        // of the shaper. We remove that to get the shaper for each actual document being read (as opposed to the page of those documents),\n        // and extract the pagination arguments.\n        if (shaperBody is PagingExpression pagingExpression)\n        {\n            paging = true;\n            maxItemCount = pagingExpression.MaxItemCount;\n            continuationToken = pagingExpression.ContinuationToken;\n            responseContinuationTokenLimitInKb = pagingExpression.ResponseContinuationTokenLimitInKb;\n\n            shaperBody = pagingExpression.Expression;\n        }\n\n        if (shapedQueryExpression.QueryExpression is not SelectExpression selectExpression)\n        {\n            throw new NotSupportedException(CoreStrings.UnhandledExpressionNode(shapedQueryExpression.QueryExpression));\n        }\n\n        VerifyNoClientConstant(shaperBody);\n\n        // Because the shaper might process the data twice (duplicated shaper),\n        // we pass the data as ROM, and the shaper will create a JsonReaderData where needed.\n        var dataParameter = Parameter(typeof(ReadOnlyMemory<byte>), \"data\");\n        // The shaper will always read the whole next json token/object, and will know how many bytes that was\n        // we get the amount of bytes read from the shaper, so that we can advance the data in the QueryingEnumerable as needed, without having to scan the data twice (once for shaper, once for advancing the data).\n        var bytesConsumedParameter = Parameter(typeof(int).MakeByRefType(), \"bytesConsumed\");\n        var shaperLambda = new ShaperProcessingExpressionVisitor(this, selectExpression, dataParameter, bytesConsumedParameter)\n            .ProcessShaper(shaperBody);\n\n        var cosmosQueryContextConstant = Convert(QueryCompilationContext.QueryContextParameter, typeof(CosmosQueryContext));\n        var shaperConstant = Constant(shaperLambda.Compile());\n        var contextTypeConstant = Constant(_contextType);\n        var rootEntityTypeConstant = Constant(rootEntityType);\n        var threadSafetyConstant = Constant(_threadSafetyChecksEnabled);","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs#L44-L80","documentation":"Thrown when the shaped query's underlying QueryExpression is not a SelectExpression. The Cosmos shaper compiler only knows how to compile a Cosmos SelectExpression; any other expression type as the query root is an unexpected, unsupported state that triggers NotSupportedException.","triggerScenarios":"Internal: the query pipeline produced a non-SelectExpression QueryExpression for a Cosmos query. Externally rare; typically indicates a bug in the provider or an unsupported query construct that bypassed normal SelectExpression construction.","commonSituations":"Provider version bugs, combining Cosmos with providers incorrectly, or using internal/extensibility APIs that inject non-SelectExpression nodes. After upgrading EF Core with a regression.","solutions":["Simplify the query to rule out an unsupported construct triggering the path.","Upgrade to the latest EF Core Cosmos patch; if it persists, report a bug with the query.","Avoid mixing providers or internal query APIs with Cosmos queries.","Reproduce with the minimal query and file an issue in the EF Core repo."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    return await query.ToListAsync();\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Unhandled expression node\"))\n{\n    logger.LogCritical(ex, \"Unsupported query shape; report to EF Core\");\n    throw;\n}","preventionTips":["Avoid mixing providers or internal query APIs with Cosmos.","Keep EF Core Cosmos updated to the latest patch.","Reproduce with a minimal query and report if it persists."],"tags":["cosmos","query","shaper","select-expression","unsupported"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}