Fix ComplexProperty treated as nullable after update from EF Core 9.0 to 10.0#38045
Draft
Fix ComplexProperty treated as nullable after update from EF Core 9.0 to 10.0#38045
Conversation
…me and design-time paths The fix addresses two issues: 1. Add version-aware complex property nullability update in Migrator.FinalizeModel() for the runtime path (MigrateAsync/HasPendingModelChanges) 2. Fix SnapshotModelProcessor to handle property bag complex types (Dictionary<string, object>) used in real snapshots, not just struct CLR types Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/2031c264-97cc-4867-911e-555cb81e8f9b Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ComplexProperty treatment as nullable after EF Core update
Fix ComplexProperty treated as nullable after update from EF Core 9.0 to 10.0
Apr 4, 2026
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.
Upgrading from EF Core 9.0 to 10.0 with struct complex properties causes false
PendingModelChangesWarningduringMigrateAsyncand spuriousAlterColumnmigrations marking columns asoldNullable: true.Two bugs:
SnapshotModelProcessor(design-time/CLI path). The runtime path throughMigrator.FinalizeModel()→HasPendingModelChanges()was never covered —SnapshotModelProcessoris not instantiated at runtime.UpdateComplexPropertyNullabilityguarded on!complexProperty.ClrType.IsNullableType(), but snapshot models usetypeof(Dictionary<string, object>)(property bag format) as the CLR type, not the actual struct type. The guard always evaluated tofalsefor real snapshots, so the fix never applied.Changes
Migrator.FinalizeModel()— Added version-aware nullability fixup for pre-10.0 snapshots before calling_modelRuntimeInitializer.Initialize(). In 9.x, optional complex properties didn't exist, so all complex properties are unconditionally set to non-nullable.SnapshotModelProcessor.UpdateComplexPropertyNullability()— Removed the!ClrType.IsNullableType()guard. The version check alone is sufficient since EF Core 8.x/9.x had no optional complex property support.HasPendingModelChangeswith property-bag snapshot format) and design-time-path test (property-bag complex property throughSnapshotModelProcessor).