dotnet/efcore · error · InvalidOperationException

Navigation '{entityType}.{navigationName}' doesn't point to

Error message

Navigation '{entityType}.{navigationName}' doesn't point to an embedded entity.

What it means

ObjectArrayAccessExpression reads a JSON array of embedded objects (used for collection navigations/complex collections). Like its single-object counterpart, it throws InvalidOperationException when given a navigation whose target is not embedded (no containing property name). Only embedded collection navigations are representable on Cosmos.

Source

Thrown at src/EFCore.Cosmos/Query/Internal/Expressions/ObjectArrayAccessExpression.cs:40

    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public ObjectArrayAccessExpression(
        Expression @object,
        IPropertyBase structuralProperty,
        StructuralTypeProjectionExpression? innerProjection = null)
    {
        ITypeBase targetType;
        string propertyName;

        switch (structuralProperty)
        {
            case INavigation navigation:
                targetType = navigation.TargetEntityType;
                propertyName = navigation.TargetEntityType.GetContainingPropertyName()
                    ?? throw new InvalidOperationException(
                        CosmosStrings.NavigationPropertyIsNotAnEmbeddedEntity(
                            navigation.DeclaringEntityType.DisplayName(), navigation.Name));
                break;
            case IComplexProperty complexProperty:
                targetType = complexProperty.ComplexType;
                propertyName = complexProperty.GetJsonPropertyName();
                break;
            default:
                throw new UnreachableException($"Unexpected structural property type: {structuralProperty.GetType().FullName}");
        }

        PropertyName = propertyName;
        Type = typeof(IEnumerable<>).MakeGenericType(targetType.ClrType);
        StructuralProperty = structuralProperty;
        Object = @object;
        InnerProjection = innerProjection
            ?? new StructuralTypeProjectionExpression(new ObjectReferenceExpression(targetType, ""), targetType);
    }

View on GitHub (pinned to dbf9771522)

Solutions

  1. Map the collection as embedded owned: builder.Entity<Root>().OwnsMany(r => r.Items).
  2. Avoid server-side queries over non-embedded collections; load the root and filter client-side, or split into separate container queries.
  3. Use a complex collection (complex type list) if the children are value objects.

Example fix

// before
var q = ctx.Orders.Where(o => o.Items.Any(i => i.Sku == "x"));
// where Items is a plain navigation -> throws

// after
modelBuilder.Entity<Order>().OwnsMany(o => o.Items);
var q = ctx.Orders.Where(o => o.Items.Any(i => i.Sku == "x"));
Defensive patterns

Strategy: validation

Validate before calling

static bool IsEmbeddedCollection(INavigation n)
    => n.IsCollection && n.TargetEntityType.GetContainingPropertyName() is not null;
var nav = cosmosModel.FindEntityType(typeof(Order))!.FindNavigation(nameof(Order.Items))!;
if (!IsEmbeddedCollection(nav))
    throw new InvalidOperationException("Configure Items as OwnsMany.");

Type guard

static bool CollectionNavigationIsEmbedded(IEntityType owner, string navName)
    => owner.FindNavigation(navName) is { IsCollection: true } n
       && n.TargetEntityType.GetContainingPropertyName() is not null;

Try / catch

try { var q = ctx.Orders.Where(o => o.Items.Any(i => i.Sku == "x")).ToList(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("doesn't point to an embedded entity"))
{ /* map as OwnsMany or filter client-side */ }

Prevention

When it happens

Trigger: Querying a collection navigation (e.g. .SelectMany, .Any on children) that is not configured as OwnsMany/complex collection, so Cosmos cannot embed it.

Common situations: Relational-style one-to-many FK collections migrated to Cosmos without OwnsMany; querying child collections as if joins existed.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/bdd58372c0cd50c0. Report an issue: GitHub.