Fix the check for null required nested complex properties#36406
Fix the check for null required nested complex properties#36406AndriySvyryd merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the null validation logic for required nested complex properties in Entity Framework Core. The issue was that EF Core was incorrectly throwing validation errors for required properties within complex types when the parent complex type itself was null, which should be allowed.
- Removes workaround configuration that marked required nested complex properties as optional
- Updates null validation logic to properly handle nested complex properties within optional parent complex types
- Ensures validation only occurs when the parent complex type is non-null
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| ComplexJsonRelationalFixtureBase.cs | Removes TODO comment and workaround configuration, allowing RequiredNested to use its natural required configuration |
| InternalEntryBase.cs | Updates null validation logic for both collections and complex properties to check parent complex type nullability |
| // TODO: Currently everything within an optional complex type must be configured as optional - seems wrong. | ||
| // #36402 | ||
| orb.ComplexProperty(r => r.RequiredNested).IsRequired(false); | ||
| orb.ComplexProperty(r => r.RequiredNested); |
There was a problem hiding this comment.
Should be removable altogether no?
There was a problem hiding this comment.
Not until I change the navigation discovery convention logic
There was a problem hiding this comment.
I might be cnofused, but looking at the configuration just above - for RequiredRelated - the configuration for RequiredNested is omitted there. And yet I can see it mapped as a complex JSON property (e.g. see test Where_nested_related_property for SQL Server)...
Fixes #36402