Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

Fixes #37386

When optional complex properties transition from null to non-null with default-valued properties (e.g., new LockInfo(default(DateTimeOffset))), those default values were not being tracked or saved to the database.

Changes

  • Change Detection: Enhanced ChangeDetector.PropertyChanged to detect when non-collection complex properties transition from null to non-null
  • Property Modification: When a complex property changes from null to non-null, all saveable inner properties are now marked as modified to ensure they are persisted (even with default values)
  • Test Coverage: Added comprehensive tests for optional complex properties with default values
  • Test Infrastructure: Updated ExecuteWithStrategyInTransactionAsync to support 4 nested test operations in base class and all derived test classes (InMemory and Cosmos)

Testing

  • ✅ All API consistency tests pass
  • ✅ Sqlite tests pass including discriminator and multi-property tests
  • ✅ Existing tests pass, confirming the fix doesn't break existing functionality
  • ✅ InMemory multi-property test is now properly skipped due to provider limitation (issue Fully support complex types with the InMemory provider #31464)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix tracking of default values in optional complex properties Fix: Track default values when optional complex properties transition from null Dec 16, 2025
Copilot AI requested a review from AndriySvyryd December 16, 2025 18:55
Copilot AI requested a review from AndriySvyryd December 16, 2025 23:36
@AndriySvyryd AndriySvyryd changed the base branch from release/10.0 to main January 7, 2026 19:52
@AndriySvyryd AndriySvyryd force-pushed the copilot/fix-optional-complex-properties branch from 69cf1bd to 1b84b81 Compare January 7, 2026 19:53
@AndriySvyryd AndriySvyryd changed the title Fix: Track default values when optional complex properties transition from null Fix optional complex property default values tracking Jan 7, 2026
@AndriySvyryd AndriySvyryd force-pushed the copilot/fix-optional-complex-properties branch from 1b84b81 to f45d77d Compare January 7, 2026 19:57
@AndriySvyryd AndriySvyryd marked this pull request as ready for review January 7, 2026 19:58
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner January 7, 2026 19:58
Copilot AI review requested due to automatic review settings January 7, 2026 19:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #37386 where default values in optional complex properties were not being tracked or saved to the database when the complex property transitions from null to a non-null value with default-valued properties.

Key Changes

  • Enhanced change detection logic to detect when nullable complex properties transition between null and non-null states
  • When a complex property changes from null to non-null, all inner properties are now marked as modified to ensure they are persisted (even with default values)
  • Added comprehensive test coverage for the scenario with multiple properties having default values

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/EFCore/ChangeTracking/Internal/ChangeDetector.cs Added DetectComplexPropertyChange method to detect null/non-null transitions and mark inner properties as modified; integrated this detection into both PropertyChanged and LocalDetectChanges methods
test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs Added test Can_save_default_values_in_optional_complex_property_with_multiple_properties with entity and complex type definitions; updated ExecuteWithStrategyInTransactionAsync signature to support a third nested operation
test/EFCore.SqlServer.FunctionalTests/ComplexTypesTrackingSqlServerTest.cs Skipped the new test for proxies fixture since complex types with notification change tracking are not yet supported (Issue #36175)

…ory tests

Updated the method signature to include nestedTestOperation3 parameter to match the base class, which was updated to support 4 nested test operations.

Co-authored-by: AndriySvyryd <[email protected]>
Updated the method signature to include nestedTestOperation3 parameter to match the base class, which was updated to support 4 nested test operations.

Co-authored-by: AndriySvyryd <[email protected]>
@AndriySvyryd AndriySvyryd marked this pull request as draft January 8, 2026 00:13
… PropertySaveBehavior

- Made DetectComplexPropertyChange virtual to satisfy API consistency requirements
- Updated logic to only mark properties with AfterSaveBehavior == Save to avoid modifying read-only properties like discriminators
- Fixes ApiConsistencyTest.Public_inheritable_apis_should_be_virtual
- Fixes AdHocComplexTypeQuerySqliteTest.Optional_complex_type_with_discriminator
- Sqlite tests for multi-property complex types now pass

Co-authored-by: AndriySvyryd <[email protected]>
…le_properties in InMemory tests

Override the test method to return Task.CompletedTask, effectively skipping it for InMemory provider due to query compilation issues with complex types. References issue #31464.

Co-authored-by: AndriySvyryd <[email protected]>
@AndriySvyryd AndriySvyryd marked this pull request as ready for review January 8, 2026 01:30
@AndriySvyryd AndriySvyryd requested review from a team and Copilot January 8, 2026 01:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default values in optional complex properties are not tracked/saved

2 participants