Skip to content

Commit b17ddcc

Browse files
Copilotroji
authored andcommitted
Document Cosmos: empty owned collections now return empty instead of null (#5301)
See dotnet/efcore#36577
1 parent 41de6d0 commit b17ddcc

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

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
@@ -23,9 +23,10 @@ This page documents API and behavior changes that have the potential to break ex
2323
|:--------------------------------------------------------------------------------------------------------------- | -----------|
2424
| [Sync I/O via the Azure Cosmos DB provider has been fully removed](#cosmos-nosync) | Medium |
2525
| [EF Core now throws by default when no migrations are found](#migrations-not-found) | Low |
26-
| [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low |
27-
| [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low |
26+
| [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low |
27+
| [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low |
2828
| [SqlVector properties are no longer loaded by default](#sqlvector-not-auto-loaded) | Low |
29+
| [Cosmos: empty owned collections now return an empty collection instead of null](#cosmos-empty-collections) | Low |
2930

3031
## Medium-impact changes
3132

@@ -179,6 +180,42 @@ var embeddings = await context.Blogs
179180
.ToListAsync();
180181
```
181182

183+
<a name="cosmos-empty-collections"></a>
184+
185+
### Cosmos: empty owned collections now return an empty collection instead of null
186+
187+
[Tracking Issue #36577](https://github.com/dotnet/efcore/issues/36577)
188+
189+
#### Old behavior
190+
191+
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.
192+
193+
#### New behavior
194+
195+
Starting with EF Core 11.0, the Azure Cosmos DB provider correctly initializes empty owned collections, returning an empty collection instead of `null`.
196+
197+
#### Why
198+
199+
The previous behavior of materializing empty owned collections as `null` was a bug.
200+
201+
#### Mitigations
202+
203+
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:
204+
205+
```csharp
206+
// Before
207+
if (entity.OwnedCollection is null or { Count: 0 })
208+
{
209+
// treated as empty
210+
}
211+
212+
// After
213+
if (entity.OwnedCollection is { Count: 0 })
214+
{
215+
// treated as empty
216+
}
217+
```
218+
182219
<a name="MDS-breaking-changes"></a>
183220

184221
## Microsoft.Data.Sqlite breaking changes

0 commit comments

Comments
 (0)