{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs#L317-L353","documentation":"Thrown by CosmosProjectionBindingExpressionVisitor when a MaterializeCollectionNavigationExpression is processed and the navigation is not an embedded collection (Navigation.IsEmbedded() is false). Cosmos EF Core only supports server-side Include for navigations that are stored as embedded JSON arrays inside the same document; a related entity stored in a separate container cannot be joined at query time. The message names the navigation.","triggerScenarios":"Calling .Include(x => x.RelatedCollection) where RelatedCollection is a navigation not configured as embedded (it maps to a separate Cosmos container or is a pure relationship without embedded storage), inside a query that triggers materialization of that collection.","commonSituations":"Treating Cosmos like a relational DB and defining one-to-many relationships across separate containers expecting them to join. Including navigations on entities migrated from SQL Server without marking them embedded.","solutions":["Configure the navigation as embedded: own the collection (OwnsMany) so its data lives inside the same Cosmos document, then Include works.","If the related data must live in a separate container, issue a separate query by key and stitch results client-side instead of using Include."],"exampleFix":"// before\npublic class Order {\n    public List<OrderItem> Items { get; set; } // separate container\n}\nvar orders = await db.Orders.Include(o => o.Items).ToListAsync();\n\n// after: embed items inside the order document\nmodelBuilder.Entity<Order>().OwnsMany(o => o.Items);\nvar orders = await db.Orders.Include(o => o.Items).ToListAsync();","handlingStrategy":"validation","validationCode":"// Assert navigations used with Include are embedded before running queries\nforeach (var nav in typeof(MyContext).Assembly.GetTypes()\n            .SelectMany(t => t.GetProperties())\n            .Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(List<>)))\n{\n    // cross-check against modelBuilder: ensure OwnsMany is declared for each included collection\n}","typeGuard":"static bool IsEmbeddedCollection(INavigation n) => n.IsEmbedded();","tryCatchPattern":null,"preventionTips":["Configure related data as embedded (OwnsMany) when you intend to Include it server-side on Cosmos.","Do not model cross-container joins expecting Include to fetch them; query separately."],"tags":["cosmos","ef-core","query","include","embeddings","navigation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}