dotnet/efcore · error · NotImplementedException

Bind property on structural type coming out of scalar subque

Error message

Bind property on structural type coming out of scalar subquery

What it means

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.

Source

Thrown at src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs:1012

                var structuralTypeProjection = (StructuralTypeProjectionExpression)valueBufferExpression;

                expression = member switch
                {
                    { MemberInfo: { } memberInfo }
                        => structuralTypeProjection.BindMember(
                            memberInfo, typeReference.Type, clientEval: false, out property),

                    { Name: { } name }
                        => structuralTypeProjection.BindMember(
                            name, typeReference.Type, clientEval: false, out property),

                    _ => throw new UnreachableException()
                };

                break;

            case { Subquery: not null }:
                throw new NotImplementedException("Bind property on structural type coming out of scalar subquery");

            default:
                throw new UnreachableException();
        }

        if (expression is null)
        {
            AddTranslationErrorDetails(
                CoreStrings.QueryUnableToTranslateMember(
                    member.Name,
                    typeReference.StructuralType.DisplayName()));
            return false;
        }

        Check.DebugAssert(property is not null, "Property cannot be null if binding result was non-null");

        switch (expression)
        {

View on GitHub (pinned to 3a2006ef56)

Solutions

  1. Restructure the query so the inner member is projected inside the subquery rather than bound outside it.
  2. Materialize the subquery result with AsEnumerable() before drilling into members.
  3. Replace the scalar subquery with a join or a direct navigation access where possible.

Example fix

// before
var q = db.Orders
    .Select(o => new { Cust = o.Customer.LatestOrder })
    .Select(x => x.Cust.OrderDate);

// after - project the scalar directly inside the inner query
var q = db.Orders
    .Select(o => o.Customer.LatestOrder.OrderDate);
Defensive patterns

Strategy: fallback

Try / catch

try { return await query.ToListAsync(); }
catch (NotImplementedException ex) when (ex.Message.Contains("scalar subquery"))
{ return query.AsEnumerable().ToList(); }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/439d7020a19dcc78. Report an issue: GitHub.