Skip to content

Commit 35ff36a

Browse files
authored
Address review feedback: fix tracking issue link and add naked projection docs
1 parent 49c1974 commit 35ff36a

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

entity-framework/core/providers/cosmos/querying.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,28 @@ var results = await context.Entities
236236
.ToListAsync();
237237
```
238238

239+
### Naked projections and SELECT VALUE
240+
241+
A _naked projection_ — where a single value is projected directly without wrapping it in a DTO or anonymous type — is translated using `SELECT VALUE` in Cosmos DB SQL. As a result, any documents where the projected value is `undefined` are **silently skipped** and not included in the results:
242+
243+
```csharp
244+
// Naked projection - translated as SELECT VALUE, undefined results are silently omitted
245+
var ids = await context.Entities
246+
.Select(x => x.Associate!.NestedAssociate!.Id)
247+
.ToListAsync();
248+
```
249+
250+
In contrast, any top-level instantiation in the projection (anonymous type, DTO, entity, or complex type) does **not** use `SELECT VALUE`. When a part of such a projection is `undefined`, an `InvalidOperationException` is thrown as described above.
251+
252+
If silently skipping undefined results is not the desired behavior, wrap the projected value in an anonymous type or DTO to get a consistent error instead:
253+
254+
```csharp
255+
// Wrapped in an anonymous type - does not use SELECT VALUE, throws if undefined
256+
var results = await context.Entities
257+
.Select(x => new { x.Associate!.NestedAssociate!.Id })
258+
.ToListAsync();
259+
```
260+
239261
## Function mappings
240262

241263
This section shows which .NET methods and members are translated into which SQL functions when querying with the Azure Cosmos DB provider.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ If your application uses composite keys whose values can contain the characters
131131

132132
### Cosmos: exception thrown when a projection evaluates to undefined
133133

134-
[Tracking Issue #38550](https://github.com/dotnet/efcore/pull/38550)
134+
[Tracking Issue #34067](https://github.com/dotnet/efcore/issues/34067)
135135

136136
#### Old behavior
137137

0 commit comments

Comments
 (0)