{"record":{"id":"b03b7ec2a34fcafc","repo":"dotnet/efcore","slug":"jsoncantnavigatetoparententity","errorCode":"JsonCantNavigateToParentEntity","errorMessage":"Navigation from JSON-mapped entity '{jsonEntity}' to its parent entity '{parentEntity}' using navigation '{navigation}' is not supported. Entities mapped to JSON can only navigate to their children.","messagePattern":"Navigation from JSON-mapped entity '(.+?)' to its parent entity '(.+?)' using navigation '(.+?)' is not supported\\. Entities mapped to JSON can only navigate to their children\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/JsonQueryExpression.cs","lineNumber":171,"sourceCode":"    /// <param name=\"structuralProperty\">The navigation or complex property to bind.</param>\n    /// <returns>An JSON query expression for the target entity or complex type.</returns>\n    public virtual JsonQueryExpression BindStructuralProperty(IPropertyBase structuralProperty)\n    {\n        switch (structuralProperty)\n        {\n            case INavigation navigation:\n            {\n                if (StructuralType is not IEntityType entityType)\n                {\n                    throw new UnreachableException(\"Navigation on complex JSON type\");\n                }\n\n                Check.DebugAssert(KeyPropertyMap is not null);\n\n                if (navigation.ForeignKey.DependentToPrincipal == navigation)\n                {\n                    // issue #28645\n                    throw new InvalidOperationException(\n                        RelationalStrings.JsonCantNavigateToParentEntity(\n                            navigation.ForeignKey.DeclaringEntityType.DisplayName(),\n                            navigation.ForeignKey.PrincipalEntityType.DisplayName(),\n                            navigation.Name));\n                }\n\n                var targetEntityType = navigation.TargetEntityType;\n                var newPath = Path.ToList();\n                newPath.Add(new PathSegment(GetJsonElement(navigation).PropertyName!));\n\n                var newKeyPropertyMap = new Dictionary<IProperty, ColumnExpression>();\n                var targetPrimaryKeyProperties = targetEntityType.FindPrimaryKey()!.Properties.Take(KeyPropertyMap.Count);\n                var sourcePrimaryKeyProperties = entityType.FindPrimaryKey()!.Properties.Take(KeyPropertyMap.Count);\n                foreach (var (target, source) in targetPrimaryKeyProperties.Zip(sourcePrimaryKeyProperties, (t, s) => (t, s)))\n                {\n                    newKeyPropertyMap[target] = KeyPropertyMap[source];\n                }\n","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Query/JsonQueryExpression.cs#L153-L189","documentation":"Thrown by JsonQueryExpression.BindStructuralProperty (JsonQueryExpression.cs:171) when the navigation being bound is a dependent-to-principal navigation (i.e. it points back to the parent entity). Entities mapped to JSON columns can only navigate to their children (deeper into the JSON), never back up to a parent entity stored in a separate table (issue #28645). EF cannot express such a join from inside the JSON document, so it throws.","triggerScenarios":"Querying a JSON-mapped owned entity and traversing a navigation that points to its parent (the owning entity). E.g. ctx.Set<OwnedChildJsonEntity>()... .Select(c => c.Parent). The navigation is the FK's back-reference (DependentToPrincipal), which EF detects at line 168.","commonSituations":"Modeling an owned type mapped ToJson and then trying to navigate from it back to the owner; bidirectional navigation between a JSON-mapped owned type and its principal; querying the JSON entity directly and joining back to the parent.","solutions":["Query from the parent side and navigate down into the JSON-mapped child (the supported direction): ctx.Parents.Select(p => p.JsonChild).","If you must start from the child, load it and then look up the parent by key in a separate query rather than via the navigation.","Consider mapping the entity to a regular table (not ToJson) if bidirectional navigation from child to parent is essential.","Remove or avoid using the dependent-to-principal navigation in JSON-mapped queries."],"exampleFix":"// before - navigating from a JSON-mapped owned entity back to its parent\nvar parents = ctx.Set<ContactInfo>() // ContactInfo is owned, mapped ToJson\n    .Where(ci => ci.Phone == \"555\")\n    .Select(ci => ci.ParentContact) // JsonCantNavigateToParentEntity\n    .ToList();\n\n// after - query from the parent and navigate down (supported direction)\nvar contacts = ctx.Contacts\n    .Where(c => c.Details.Phone == \"555\")\n    .ToList();","handlingStrategy":"validation","validationCode":"// Query from the parent downward into JSON children (supported direction).\nvar q = ctx.Contacts.Where(c => c.Details.Phone == \"555\").ToList();\n// Avoid: ctx.Set<ContactInfo>().Select(ci => ci.ParentContact) // not supported","typeGuard":"// Avoid dependent-to-principal navigations on JSON-mapped entities.\nstatic bool IsParentNavigation(INavigation n)\n    => n.ForeignKey.DependentToPrincipal == n && n.DeclaringEntityType.IsMappedToJson();","tryCatchPattern":null,"preventionTips":["Navigate from parent to JSON child, not the reverse.","Do not rely on dependent-to-principal navigations for JSON-mapped owned types.","If reverse navigation is essential, map the entity to a table instead of ToJson.","Document JSON navigation restrictions (children only) for your team."],"tags":["ef-core","json","owned-type","navigation","query"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}