{"record":{"id":"ae6ff075b03faeda","repo":"dotnet/efcore","slug":"navigation-entitytype-navigationname-doesn-t","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/ObjectAccessExpression.cs","lineNumber":38,"sourceCode":"    /// <summary>\n    ///     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 ObjectAccessExpression(\n        Expression @object,\n        IPropertyBase structuralProperty)\n    {\n        ITypeBase structuralType;\n        string propertyName;\n\n        switch (structuralProperty)\n        {\n            case INavigation navigation:\n                structuralType = 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                structuralType = 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        StructuralProperty = structuralProperty;\n        Object = @object;\n        StructuralType = structuralType;\n    }\n\n    /// <summary>","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Query/Internal/Expressions/ObjectAccessExpression.cs#L20-L56","documentation":"ObjectAccessExpression's constructor throws when an INavigation is being bound as a single-object access but the navigation's target entity type has no containing property name (GetContainingPropertyName() returns null). In Cosmos, single-object navigations must point to embedded (owned) entities; a navigation whose target is not owned has no JSON path to bind against.","triggerScenarios":"Querying through a reference navigation whose target type was not configured as owned (ToOwnership/OwnsOne) in OnModelCreating.","commonSituations":"Defining a HasOne/WithMany relationship between two entities without making the target owned, then including or projecting that navigation in a Cosmos query.","solutions":["Configure the navigation target as owned: modelBuilder.Entity<T>().OwnsOne(x => x.Navigation).","Verify GetContainingPropertyName() on the target entity type returns a value (it is embedded).","Avoid querying through that navigation if it should remain a separate document relationship."],"exampleFix":"// before\nmodelBuilder.Entity<Order>().HasOne(o => o.Customer).WithMany();\n\n// after - customer is embedded inside the order document\nmodelBuilder.Entity<Order>().OwnsOne(o => o.Customer);","handlingStrategy":"validation","validationCode":"// Validate at model build time that reference navigations used in Cosmos queries are owned.\nforeach (var nav in entityType.GetNavigations().Where(n => !n.IsCollection && n.TargetEntityType.GetContainingPropertyName() == null))\n{\n    throw new InvalidOperationException($\"Navigation {entityType.DisplayName()}.{nav.Name} is not embedded; configure OwnsOne.\");\n}","typeGuard":"static bool IsEmbeddedNavigation(INavigation n) => n.TargetEntityType.GetContainingPropertyName() is not null;","tryCatchPattern":null,"preventionTips":["For Cosmos providers, configure all reference navigations you query through with OwnsOne.","Add a model validation hook that rejects non-embedded navigations during OnModelCreating.","Run CreateContainer/EnsureCreated early in dev to surface embedding issues."],"tags":["cosmos","model","navigation","embedded"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}