{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs#L44-L80","documentation":"CosmosShapedQueryCompilingExpressionVisitor expects the ShapedQueryExpression's QueryExpression to be a Cosmos SelectExpression. If it is any other Expression subtype (e.g. a relational SelectExpression leak, or a custom shaper that wraps a different query expression), the visitor throws NotSupportedException CoreStrings.UnhandledExpressionNode.","triggerScenarios":"A ShapedQueryExpression whose QueryExpression is not the Cosmos SelectExpression — typically from mixing providers in one query, custom IQueryCompiler extensions, or reusing a compiled query across providers.","commonSituations":"Running a query compiled against a relational context through a Cosmos context, sharing query compilation code across providers, or third-party EF extensions that build ShapedQueryExpression manually.","solutions":["Ensure the DbContext and the DbSet both use the Cosmos provider end-to-end.","Do not share compiled queries or expression trees across providers.","If extending the query pipeline, always return a Cosmos SelectExpression from your visitor."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure provider consistency\nstatic void AssertCosmos(DbContext ctx)\n{\n    if (ctx.Database.ProviderName != \"Microsoft.EntityFrameworkCore.Cosmos\")\n        throw new InvalidOperationException(\"Context is not using the Cosmos provider.\");\n}","typeGuard":"static bool IsCosmosContext(DbContext ctx)\n    => ctx.Database.ProviderName == \"Microsoft.EntityFrameworkCore.Cosmos\";","tryCatchPattern":null,"preventionTips":["Do not share compiled queries across providers.","Validate ProviderName before executing.","Custom query extensions must return Cosmos SelectExpression instances."],"tags":["cosmos","query-translation","shaper","provider"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}