{"record":{"id":"439d7020a19dcc78","repo":"dotnet/efcore","slug":"bind-property-on-structural-type-coming-out-of-sca","errorCode":null,"errorMessage":"Bind property on structural type coming out of scalar subquery","messagePattern":"Bind property on structural type coming out of scalar subquery","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs","lineNumber":1012,"sourceCode":"                var structuralTypeProjection = (StructuralTypeProjectionExpression)valueBufferExpression;\n\n                expression = member switch\n                {\n                    { MemberInfo: { } memberInfo }\n                        => structuralTypeProjection.BindMember(\n                            memberInfo, typeReference.Type, clientEval: false, out property),\n\n                    { Name: { } name }\n                        => structuralTypeProjection.BindMember(\n                            name, typeReference.Type, clientEval: false, out property),\n\n                    _ => throw new UnreachableException()\n                };\n\n                break;\n\n            case { Subquery: not null }:\n                throw new NotImplementedException(\"Bind property on structural type coming out of scalar subquery\");\n\n            default:\n                throw new UnreachableException();\n        }\n\n        if (expression is null)\n        {\n            AddTranslationErrorDetails(\n                CoreStrings.QueryUnableToTranslateMember(\n                    member.Name,\n                    typeReference.StructuralType.DisplayName()));\n            return false;\n        }\n\n        Check.DebugAssert(property is not null, \"Property cannot be null if binding result was non-null\");\n\n        switch (expression)\n        {","sourceCodeStart":994,"sourceCodeEnd":1030,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs#L994-L1030","documentation":"TryBindMember in the Cosmos SQL translator throws this NotImplementedException when binding a member (property or name) against a structural type that is itself the result of a scalar subquery. The Cosmos provider cannot currently bind members off objects emitted by scalar subqueries, so this remains an unimplemented translation path. It is not a user model configuration error.","triggerScenarios":"A query that projects a scalar subquery returning a structural/object result, then immediately accesses a member of that result (e.g. selecting a navigation coming out of a subquery and drilling into a property on it).","commonSituations":"Nested projections of owned/complex types via subqueries; subqueries that produce a structural type and then feed into a member binding in the outer query.","solutions":["Restructure the query so the inner member is projected inside the subquery rather than bound outside it.","Materialize the subquery result with AsEnumerable() before drilling into members.","Replace the scalar subquery with a join or a direct navigation access where possible."],"exampleFix":"// before\nvar q = db.Orders\n    .Select(o => new { Cust = o.Customer.LatestOrder })\n    .Select(x => x.Cust.OrderDate);\n\n// after - project the scalar directly inside the inner query\nvar q = db.Orders\n    .Select(o => o.Customer.LatestOrder.OrderDate);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return await query.ToListAsync(); }\ncatch (NotImplementedException ex) when (ex.Message.Contains(\"scalar subquery\"))\n{ return query.AsEnumerable().ToList(); }","preventionTips":["Project scalar members inside subqueries rather than binding members off subquery results.","Materialize intermediate subquery results client-side when in doubt.","Track known-supported query shapes per EF Core release."],"tags":["cosmos","query-translation","subquery","not-implemented"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}