Make GetContainerColumnType() always return the expected type#37864
Merged
AndriySvyryd merged 6 commits intomainfrom Mar 6, 2026
Merged
Make GetContainerColumnType() always return the expected type#37864AndriySvyryd merged 6 commits intomainfrom
AndriySvyryd merged 6 commits intomainfrom
Conversation
… finalized models Set the default ContainerColumnType annotation during model finalization in RelationalMapToJsonConvention for JSON-mapped entity types and complex types that don't have it explicitly set. Also remove the now-dead workaround code in CSharpSnapshotGenerator that manually resolved the default JSON type. Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix GetContainerColumnType to always return expected type
Make GetContainerColumnType() always return the expected type
Mar 6, 2026
AndriySvyryd
reviewed
Mar 6, 2026
…mnType() Instead of setting the ContainerColumnType annotation in the convention, resolve the default from the type mapping source directly in the GetContainerColumnType() method when the model is finalized (read-only). Reverts the convention and snapshot generator changes. Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…ainerColumnType resolves defaults Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
AndriySvyryd
reviewed
Mar 6, 2026
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
AndriySvyryd
reviewed
Mar 6, 2026
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes GetContainerColumnType() to always return the expected JSON store type when the model is finalized, even if no explicit ContainerColumnType annotation was set by the user. Previously, the method returned null in this case, requiring callers (like CSharpSnapshotGenerator) to add their own fallback logic. The fix centralizes the default type resolution inside GetContainerColumnType() itself, using the provider's type mapping source to look up the JSON placeholder mapping.
Changes:
GetContainerColumnType()now dynamically resolves the default JSON store type from the type mapping source when the model is finalized and no explicit annotation is set, using thetypeBase.Model is not Model model || model.IsReadOnlypattern to guard against pre-finalization calls.- The redundant
?? Dependencies.RelationalTypeMappingSource.FindMapping(typeof(JsonTypePlaceholder))?.StoreTypefallback inCSharpSnapshotGeneratoris removed since it's now handled insideGetContainerColumnType(). - Two new tests verify that complex properties and complex collections get the default container column type (resolved from the type mapping source) when no explicit type is configured.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs |
Core fix: GetContainerColumnType() now resolves the default JSON store type from the type mapping source when the model is finalized |
src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs |
Removed redundant fallback — now delegated to the updated GetContainerColumnType() |
test/EFCore.Relational.Tests/Metadata/RelationalModelTest.cs |
Two new tests covering default container column type resolution for complex properties and complex collections |
You can also share your feedback on Copilot code review. Take the survey.
roji
approved these changes
Mar 6, 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.
GetContainerColumnType()always return the expected type #36647GetContainerColumnType()to resolve the default JSON store type from the type mapping source when the model is finalized and no explicit type annotation is setCSharpSnapshotGeneratortypeBase.Model is not Model model || model.IsReadOnlypattern to handle bothModeland non-Modeltypes (e.g.RuntimeModel)Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.