From 7f7846433b987b837de5e49734136f7375f5423c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 22:02:30 +0000 Subject: [PATCH 1/4] Document Cosmos empty collection null behavior change Co-authored-by: roji <1862641+roji@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/EntityFramework.Docs/sessions/24eed013-bccb-4d07-bec3-7f80f0dd3036 --- .../ef-core-11.0/breaking-changes.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md index 7d822d61ea..aa7a3e765b 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md @@ -23,6 +23,7 @@ This page documents API and behavior changes that have the potential to break ex | [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low | | [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low | | [SqlVector properties are no longer loaded by default](#sqlvector-not-auto-loaded) | Low | +| [Cosmos: empty owned collection navigations now return an empty collection instead of null](#cosmos-empty-collections) | Low | ## Medium-impact changes @@ -175,3 +176,41 @@ var embeddings = await context.Blogs .Select(b => new { b.Id, b.Embedding }) .ToListAsync(); ``` + + + +### Cosmos: empty owned collection navigations now return an empty collection instead of null + +[Tracking Issue #36577](https://github.com/dotnet/efcore/issues/36577) + +#### Old behavior + +Previously, when querying entities via the Azure Cosmos DB provider where an owned collection navigation contained no items, the navigation property was `null` on the materialized entity. + +#### New behavior + +Starting with EF Core 11.0, the Azure Cosmos DB provider correctly initializes empty owned collection navigations, returning an empty collection instead of `null`. + +#### Why + +This was a bug: collection initialization was previously triggered only during enumeration of the collection's items. When there were no items, no enumeration occurred and the collection was left uninitialized (`null`). + +#### Mitigations + +If your code explicitly checks collection navigation properties for `null` as a way to detect that the collection is empty, update those checks to also handle the empty-collection case: + +```csharp +// Before +if (entity.OwnedCollection is null) +{ + // treated as empty +} + +// After +if (entity.OwnedCollection is null or { Count: 0 }) +{ + // treated as empty +} +``` + +Alternatively, since the collection is now always initialized when the entity exists in the store, `null` checks on owned collection navigations can simply be removed. From 1892e46c2a95ce2c8bbd468fcb4551fb1c05f26c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 07:13:48 +0000 Subject: [PATCH 2/4] Address review feedback on Cosmos empty collections breaking change Co-authored-by: roji <1862641+roji@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/EntityFramework.Docs/sessions/de97c57f-87b9-45c9-9dae-e8c9ff1517cf --- .../ef-core-11.0/breaking-changes.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md index aa7a3e765b..5d2ccc0aa9 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md @@ -23,7 +23,7 @@ This page documents API and behavior changes that have the potential to break ex | [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low | | [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low | | [SqlVector properties are no longer loaded by default](#sqlvector-not-auto-loaded) | Low | -| [Cosmos: empty owned collection navigations now return an empty collection instead of null](#cosmos-empty-collections) | Low | +| [Cosmos: empty owned collections now return an empty collection instead of null](#cosmos-empty-collections) | Low | ## Medium-impact changes @@ -179,38 +179,36 @@ var embeddings = await context.Blogs -### Cosmos: empty owned collection navigations now return an empty collection instead of null +### Cosmos: empty owned collections now return an empty collection instead of null [Tracking Issue #36577](https://github.com/dotnet/efcore/issues/36577) #### Old behavior -Previously, when querying entities via the Azure Cosmos DB provider where an owned collection navigation contained no items, the navigation property was `null` on the materialized entity. +Previously, when querying entities via the Azure Cosmos DB provider where an owned collection contained no items, the collection property was `null` on the materialized entity. #### New behavior -Starting with EF Core 11.0, the Azure Cosmos DB provider correctly initializes empty owned collection navigations, returning an empty collection instead of `null`. +Starting with EF Core 11.0, the Azure Cosmos DB provider correctly initializes empty owned collections, returning an empty collection instead of `null`. #### Why -This was a bug: collection initialization was previously triggered only during enumeration of the collection's items. When there were no items, no enumeration occurred and the collection was left uninitialized (`null`). +The previous behavior of materializing empty owned collections as `null` was a bug. #### Mitigations -If your code explicitly checks collection navigation properties for `null` as a way to detect that the collection is empty, update those checks to also handle the empty-collection case: +If your code explicitly checks owned collection properties for `null` to detect that the collection is empty, those checks can simply be removed, since the collection is now always initialized: ```csharp // Before -if (entity.OwnedCollection is null) +if (entity.OwnedCollection is null or { Count: 0 }) { // treated as empty } // After -if (entity.OwnedCollection is null or { Count: 0 }) +if (entity.OwnedCollection is { Count: 0 }) { // treated as empty } ``` - -Alternatively, since the collection is now always initialized when the entity exists in the store, `null` checks on owned collection navigations can simply be removed. From b7d09d436aae16ca65c19c80211a5eea0ec4843d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 08:19:30 +0000 Subject: [PATCH 3/4] Fix table Impact column spacing to be consistent across all rows Co-authored-by: roji <1862641+roji@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/EntityFramework.Docs/sessions/c170f175-98b7-4e66-b81d-996d06159012 --- .../core/what-is-new/ef-core-11.0/breaking-changes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md index 5d2ccc0aa9..6dfc26a26f 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md @@ -23,7 +23,7 @@ This page documents API and behavior changes that have the potential to break ex | [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low | | [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low | | [SqlVector properties are no longer loaded by default](#sqlvector-not-auto-loaded) | Low | -| [Cosmos: empty owned collections now return an empty collection instead of null](#cosmos-empty-collections) | Low | +| [Cosmos: empty owned collections now return an empty collection instead of null](#cosmos-empty-collections) | Low | ## Medium-impact changes From ba2238007e61e8cb598faa1ca98ae48248d4aefe Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Tue, 24 Mar 2026 11:48:29 +0100 Subject: [PATCH 4/4] Whitespace --- .../core/what-is-new/ef-core-11.0/breaking-changes.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md index 6dfc26a26f..a6f6900733 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md @@ -20,10 +20,10 @@ This page documents API and behavior changes that have the potential to break ex |:--------------------------------------------------------------------------------------------------------------- | -----------| | [Sync I/O via the Azure Cosmos DB provider has been fully removed](#cosmos-nosync) | Medium | | [EF Core now throws by default when no migrations are found](#migrations-not-found) | Low | -| [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low | -| [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low | +| [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low | +| [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low | | [SqlVector properties are no longer loaded by default](#sqlvector-not-auto-loaded) | Low | -| [Cosmos: empty owned collections now return an empty collection instead of null](#cosmos-empty-collections) | Low | +| [Cosmos: empty owned collections now return an empty collection instead of null](#cosmos-empty-collections) | Low | ## Medium-impact changes