dotnet / dotnet/efcore

Cosmos: projecting out an owned type nested in an optional owned type throws

Open
#36,403 0 comments 1 reaction 0 assignees View on GitHub
area-cosmos area-owned-entities area-query
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

See test OwnedNavigationsProjectionCosmosTest.Select_required_nested_on_optional_related:

```c#
AssertQuery(
async,
ss => ss.Set().Select(x => x.OptionalRelated!.RequiredNested),
ss => ss.Set().Where(x => x.OptionalRelated != null).Select(x => x.OptionalRelated!.RequiredNested),
queryTrackingBehavior: queryTrackingBehavior));
```

Exception:

```
System.NullReferenceException : Object reference not set to an instance of an object.
at lambda_method803(Closure, QueryContext, JToken)
at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync() in /Users/roji/projects/efcore/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs:line 247
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken) in /Users/roji/projects/efcore/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs:line 2309
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken) in /Users/roji/projects/efcore/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs:line 2309
at Microsoft.EntityFrameworkCore.TestUtilities.QueryAsserter.AssertQuery[TResult](Func`2 actualQuery, Func`2 expectedQuery, Func`2 elementSorter, Action`2 elementAsserter, Boolean assertOrder, Boolean assertEmpty, Boolean async, Nullable`1 queryTrackingBehavior, String testMethodName, Boolean filteredQuery) in /Users/roji/projects/efcore/test/EFCore.Specification.Tests/TestUtilities/QueryAsserter.cs:line 99
at Microsoft.EntityFrameworkCore.Query.QueryTestBase`1.TestOutputWrapper(Func`1 testAction) in /Users/roji/projects/efcore/test/EFCore.Specification.Tests/Query/QueryTestBase.cs:line 1178
at Microsoft.EntityFrameworkCore.Query.Relationships.OwnedNavigations.OwnedNavigationsProjectionTestBase`1.AssertOwnedTrackingQuery(QueryTrackingBehavior queryTrackingBehavior, Func`1 test) in /Users/roji/projects/efcore/test/EFCore.Specification.Tests/Query/Relationships/OwnedNavigations/OwnedNavigationsProjectionTestBase.cs:line 246
at Microsoft.EntityFrameworkCore.Query.Relationships.OwnedNavigations.OwnedNavigationsProjectionCosmosTest.Select_required_nested_on_optional_related(Boolean async, QueryTrackingBehavior queryTrackingBehavior) in /Users/roji/projects/efcore/test/EFCore.Cosmos.FunctionalTests/Query/Relationships/OwnedNavigations/OwnedNavigationsProjectionCosmosTest.cs:line 152
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.