Fix optional complex property default values tracking#37387
Merged
AndriySvyryd merged 1 commit intomainfrom Feb 6, 2026
Merged
Fix optional complex property default values tracking#37387AndriySvyryd merged 1 commit intomainfrom
AndriySvyryd merged 1 commit intomainfrom
Conversation
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
test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs
Outdated
Show resolved
Hide resolved
69cf1bd to
1b84b81
Compare
1b84b81 to
f45d77d
Compare
There was a problem hiding this comment.
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) |
test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs
Outdated
Show resolved
Hide resolved
AndriySvyryd
reviewed
Jan 7, 2026
AndriySvyryd
reviewed
Jan 9, 2026
249ae47 to
6b86657
Compare
roji
approved these changes
Jan 31, 2026
Copilot stopped work on behalf of
AndriySvyryd due to an error
February 2, 2026 19:52
Copilot stopped work on behalf of
AndriySvyryd due to an error
February 2, 2026 20:08
6 tasks
Fixes #37386 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
3044d98 to
2832891
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ChangeDetector.PropertyChangedto detect when non-collection complex properties transition from null to non-null (using switch statement pattern)is null,is not null) to avoid issues with overridden equality operatorsExecuteWithStrategyInTransactionAsyncto support 4 nested test operations in base class and all derived test classes (InMemory and Cosmos)Testing
💡 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.