Skip to content

Make GetContainerColumnType() always return the expected type#37864

Merged
AndriySvyryd merged 6 commits intomainfrom
copilot/fix-getcontainercolumntype-issue
Mar 6, 2026
Merged

Make GetContainerColumnType() always return the expected type#37864
AndriySvyryd merged 6 commits intomainfrom
copilot/fix-getcontainercolumntype-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 6, 2026

  • Fixes Make GetContainerColumnType() always return the expected type #36647
  • Modify GetContainerColumnType() to resolve the default JSON store type from the type mapping source when the model is finalized and no explicit type annotation is set
  • Simplify redundant fallback in CSharpSnapshotGenerator
  • Use typeBase.Model is not Model model || model.IsReadOnly pattern to handle both Model and non-Model types (e.g. RuntimeModel)
Original prompt

This section details on the original issue you should resolve

<issue_title>Make GetContainerColumnType() always return the expected type</issue_title>
<issue_description>It would use the default JSON mapping in the finalized model if not specified explicitly.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

… 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
Comment thread src/EFCore.Relational/Metadata/Conventions/RelationalMapToJsonConvention.cs Outdated
Copilot AI and others added 2 commits March 6, 2026 03:12
…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>
Comment thread src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs Outdated
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Comment thread src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs Outdated
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copy link
Copy Markdown

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 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 the typeBase.Model is not Model model || model.IsReadOnly pattern to guard against pre-finalization calls.
  • The redundant ?? Dependencies.RelationalTypeMappingSource.FindMapping(typeof(JsonTypePlaceholder))?.StoreType fallback in CSharpSnapshotGenerator is removed since it's now handled inside GetContainerColumnType().
  • 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.

@AndriySvyryd AndriySvyryd marked this pull request as ready for review March 6, 2026 05:33
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner March 6, 2026 05:33
@AndriySvyryd AndriySvyryd assigned roji and unassigned AndriySvyryd and Copilot Mar 6, 2026
@roji roji removed their assignment Mar 6, 2026
@AndriySvyryd AndriySvyryd enabled auto-merge (squash) March 6, 2026 16:20
@AndriySvyryd AndriySvyryd merged commit b3caffb into main Mar 6, 2026
16 of 17 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/fix-getcontainercolumntype-issue branch March 6, 2026 18:16
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.

Make GetContainerColumnType() always return the expected type

4 participants