{"record":{"id":"bdd58372c0cd50c0","repo":"dotnet/efcore","slug":"navigation-entitytype-navigationname-doesn-t-bdd583","errorCode":null,"errorMessage":"Navigation '{entityType}.{navigationName}' doesn't point to an embedded entity.","messagePattern":"Navigation '(.+?)\\.(.+?)' doesn't point to an embedded entity\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/Expressions/ObjectArrayAccessExpression.cs","lineNumber":40,"sourceCode":"    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public ObjectArrayAccessExpression(\n        Expression @object,\n        IPropertyBase structuralProperty,\n        StructuralTypeProjectionExpression? innerProjection = null)\n    {\n        ITypeBase targetType;\n        string propertyName;\n\n        switch (structuralProperty)\n        {\n            case INavigation navigation:\n                targetType = navigation.TargetEntityType;\n                propertyName = navigation.TargetEntityType.GetContainingPropertyName()\n                    ?? throw new InvalidOperationException(\n                        CosmosStrings.NavigationPropertyIsNotAnEmbeddedEntity(\n                            navigation.DeclaringEntityType.DisplayName(), navigation.Name));\n                break;\n            case IComplexProperty complexProperty:\n                targetType = complexProperty.ComplexType;\n                propertyName = complexProperty.GetJsonPropertyName();\n                break;\n            default:\n                throw new UnreachableException($\"Unexpected structural property type: {structuralProperty.GetType().FullName}\");\n        }\n\n        PropertyName = propertyName;\n        Type = typeof(IEnumerable<>).MakeGenericType(targetType.ClrType);\n        StructuralProperty = structuralProperty;\n        Object = @object;\n        InnerProjection = innerProjection\n            ?? new StructuralTypeProjectionExpression(new ObjectReferenceExpression(targetType, \"\"), targetType);\n    }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Query/Internal/Expressions/ObjectArrayAccessExpression.cs#L22-L58","documentation":"ObjectArrayAccessExpression's constructor throws when a collection INavigation is being bound as an array access but the navigation's target entity type has no containing property name (GetContainingPropertyName() returns null). Cosmos collection navigations must point to embedded (owned) collections so the provider can express them as a JSON array path.","triggerScenarios":"Querying through a collection navigation whose target type was not configured as an owned collection (OwnsMany) in OnModelCreating.","commonSituations":"Defining a one-to-many relationship between two top-level entities without marking the many-side as owned, then projecting or filtering through the collection.","solutions":["Configure the collection target as owned: modelBuilder.Entity<T>().OwnsMany(x => x.Items).","Verify GetContainingPropertyName() on the target entity type returns a value.","Do not query through the collection if it represents cross-document relationships."],"exampleFix":"// before\nmodelBuilder.Entity<Order>().HasMany(o => o.Items).WithOne();\n\n// after - items are embedded inside the order document\nmodelBuilder.Entity<Order>().OwnsMany(o => o.Items);","handlingStrategy":"validation","validationCode":"// Validate collection navigations are embedded before they are queried.\nforeach (var nav in entityType.GetNavigations().Where(n => n.IsCollection && n.TargetEntityType.GetContainingPropertyName() == null))\n{\n    throw new InvalidOperationException($\"Collection navigation {entityType.DisplayName()}.{nav.Name} is not embedded; configure OwnsMany.\");\n}","typeGuard":"static bool IsEmbeddedCollectionNavigation(INavigation n) => n.IsCollection && n.TargetEntityType.GetContainingPropertyName() is not null;","tryCatchPattern":null,"preventionTips":["For Cosmos, configure all collection navigations you query through with OwnsMany.","Add a model-build validator that asserts every queried navigation is embedded.","Keep cross-document relationships out of the entity graph the Cosmos provider queries."],"tags":["cosmos","model","navigation","collection","embedded"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}