dotnet / dotnet/efcore

Query/Json: inconsistent behavior around missing required navigations in JSON entities

Open
#35,751 1 comment 0 reactions 0 assignees View on GitHub
area-json area-query
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

When we have a JSON entity which owns another via required navigation, we have inconsistent behavior, when that navigation is missing in the actual JSON.

If we project the owner entity, missing required navigation is materialized as null with no errors. This is because of how we process the JSON on relational - we parse the stream, so we only fill properties/navigations that we encounter data for. If there is no data for required navigation, its materialization code is not triggered and we end up with the default value (null).

However, if the required navigation is projected directly (rather than as part of an owner), we do run some validation when attempting to materialize it and throw:

`System.InvalidOperationException : Entity JsonEntityNested is required but the JSON element containing it is null.`

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.