Skip to content

Fix optional complex property default values tracking#37387

Merged
AndriySvyryd merged 1 commit intomainfrom
copilot/fix-optional-complex-properties
Feb 6, 2026
Merged

Fix optional complex property default values tracking#37387
AndriySvyryd merged 1 commit intomainfrom
copilot/fix-optional-complex-properties

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 (using switch statement pattern)
  • 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)
  • Null Checks: Using pattern matching (is null, is not null) to avoid issues with overridden equality operators
  • 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)
  • Cosmos Configuration: Added partition key configuration for test entities
  • Provider Limitations: Properly skipped tests for provider-specific limitations (InMemory issue Fully support complex types with the InMemory provider #31464, Cosmos issue Add Cosmos support for complex types #31253)

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 properly skipped due to provider limitation (issue Fully support complex types with the InMemory provider #31464)
  • ✅ Cosmos multi-property test is properly skipped due to optional complex properties not being supported (issue Add Cosmos support for complex types #31253)
  • ✅ Cosmos tests build successfully with proper partition key configuration

💡 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)

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.

Fixes #37386

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@AndriySvyryd AndriySvyryd force-pushed the copilot/fix-optional-complex-properties branch from 3044d98 to 2832891 Compare February 6, 2026 20:01
@AndriySvyryd AndriySvyryd merged commit 7c3f266 into main Feb 6, 2026
12 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/fix-optional-complex-properties branch February 6, 2026 22:40
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

3 participants