Skip to content

Commit 9087072

Browse files
authored
Document Cosmos: empty owned collections now return empty instead of null (#5301)
See dotnet/efcore#36577
1 parent 1976486 commit 9087072

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ This page documents API and behavior changes that have the potential to break ex
2020
|:--------------------------------------------------------------------------------------------------------------- | -----------|
2121
| [Sync I/O via the Azure Cosmos DB provider has been fully removed](#cosmos-nosync) | Medium |
2222
| [EF Core now throws by default when no migrations are found](#migrations-not-found) | Low |
23-
| [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low |
24-
| [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low |
23+
| [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low |
24+
| [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low |
2525
| [SqlVector properties are no longer loaded by default](#sqlvector-not-auto-loaded) | Low |
26+
| [Cosmos: empty owned collections now return an empty collection instead of null](#cosmos-empty-collections) | Low |
2627

2728
## Medium-impact changes
2829

@@ -175,3 +176,39 @@ var embeddings = await context.Blogs
175176
.Select(b => new { b.Id, b.Embedding })
176177
.ToListAsync();
177178
```
179+
180+
<a name="cosmos-empty-collections"></a>
181+
182+
### Cosmos: empty owned collections now return an empty collection instead of null
183+
184+
[Tracking Issue #36577](https://github.com/dotnet/efcore/issues/36577)
185+
186+
#### Old behavior
187+
188+
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.
189+
190+
#### New behavior
191+
192+
Starting with EF Core 11.0, the Azure Cosmos DB provider correctly initializes empty owned collections, returning an empty collection instead of `null`.
193+
194+
#### Why
195+
196+
The previous behavior of materializing empty owned collections as `null` was a bug.
197+
198+
#### Mitigations
199+
200+
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:
201+
202+
```csharp
203+
// Before
204+
if (entity.OwnedCollection is null or { Count: 0 })
205+
{
206+
// treated as empty
207+
}
208+
209+
// After
210+
if (entity.OwnedCollection is { Count: 0 })
211+
{
212+
// treated as empty
213+
}
214+
```

0 commit comments

Comments
 (0)