{"record":{"id":"5ce4d2113f91b74b","repo":"dotnet/efcore","slug":"including-navigation-navigation-is-not-support","errorCode":null,"errorMessage":"Including navigation '{navigation}' is not supported as the navigation is not embedded in same resource.","messagePattern":"Including navigation '(.+?)' is not supported as the navigation is not embedded in same resource\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs","lineNumber":335,"sourceCode":"                    {\n                        // This is to handle have correct type for the shaper expression. It is later fixed in MatchTypes.\n                        // This mirrors for structural types what we do for scalars.\n#pragma warning disable EF1001 // Internal EF Core API usage.\n                        structuralTypeShaper = structuralTypeShaper.MakeClrTypeNullable();\n#pragma warning restore EF1001 // Internal EF Core API usage.\n                    }\n                }\n\n                structuralTypeShaper = structuralTypeShaper.Update(projectionBinding);\n\n                return structuralTypeShaper;\n            }\n\n            case MaterializeCollectionNavigationExpression materializeCollectionNavigationExpression:\n                if (materializeCollectionNavigationExpression.Navigation is not INavigation includableCollectionNavigation\n                    || !includableCollectionNavigation.IsEmbedded())\n                {\n                    throw new InvalidOperationException(\n                        CosmosStrings.NonEmbeddedIncludeNotSupported(materializeCollectionNavigationExpression.Navigation));\n                }\n\n                var subquery = materializeCollectionNavigationExpression.Subquery;\n                if (subquery is MethodCallExpression { Method.IsGenericMethod: true } methodCallSubquery)\n                {\n                    // strip .Select(x => x) and .AsQueryable()\n                    if (methodCallSubquery.Method.GetGenericMethodDefinition() == QueryableMethods.Select\n                        && methodCallSubquery.Arguments[0] is MethodCallExpression selectSourceMethod)\n                    {\n                        methodCallSubquery = selectSourceMethod;\n                    }\n\n                    if (methodCallSubquery.Method.IsGenericMethod\n                        && methodCallSubquery.Method.GetGenericMethodDefinition() == QueryableMethods.AsQueryable)\n                    {\n                        subquery = methodCallSubquery.Arguments[0];\n                    }","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs#L317-L353","documentation":"Thrown by CosmosProjectionBindingExpressionVisitor when it encounters a MaterializeCollectionNavigationExpression whose Navigation is not an INavigation or is not IsEmbedded(). Cosmos only supports Include on collection navigations that are configured as embedded in the same Cosmos document; non-embedded includes cannot be served from a single document read.","triggerScenarios":"Writing ctx.Docs.Include(d => d.RelatedItems) where RelatedItems is a collection navigation that is not owned/embedded (i.e. it is a separate entity set referenced by FK).","commonSituations":"Porting a relational Include-based graph query to Cosmos; using navigation properties that look like relations but are not configured with OwnsMany/ToProperty as embedded.","solutions":["Configure the collection navigation as embedded: modelBuilder.Entity<Doc>().OwnsMany(d => d.RelatedItems) (or OwnsMany with ToProperty for the JSON path).","If the related data genuinely lives in another container/partition, drop Include and issue separate queries, joining client-side.","Confirm the navigation .IsEmbedded() returns true before using Include with it."],"exampleFix":"// before\npublic class Doc { public List<Related> RelatedItems { get; set; } }\nvar q = ctx.Docs.Include(d => d.RelatedItems);\n\n// after - embed the collection\nmodelBuilder.Entity<Doc>().OwnsMany(d => d.RelatedItems);\nvar q = ctx.Docs.Include(d => d.RelatedItems);   // now embedded, supported","handlingStrategy":"validation","validationCode":"// At startup, assert any Included collection navigation is embedded.\nforeach (var et in modelBuilder.Model.GetEntityTypes())\nforeach (var nav in et.GetNavigations().Where(n => n.IsCollection && !n.IsEmbedded()))\n    Console.Warn($\"Warning: Include({et.DisplayName()}.{nav.Name}) will throw; configure as embedded or remove Include.\");","typeGuard":"static bool CanIncludeOnCosmos(INavigation nav) => nav.IsEmbedded();","tryCatchPattern":null,"preventionTips":["Only Include navigations you have configured as owned/embedded.","For non-embedded relations, query separately and stitch client-side.","Document which navigations are embedded so Include callers know the supported set."],"tags":["cosmos","linq","include","embedded","navigation","query-translation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}