KEMBAR78
Allow configuring the column type with ToJson() by AndriySvyryd · Pull Request #36478 · dotnet/efcore · GitHub
Skip to content

Conversation

@AndriySvyryd
Copy link
Member

@AndriySvyryd AndriySvyryd commented Jul 31, 2025

Map the discriminator property to $type in JSON by default

Fixes #31252

cc @artl93

Map the discriminator property to $type in JSON by default
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner July 31, 2025 23:34
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 enables configuring column types for JSON columns when using ToJson() with complex properties and collections. It also implements the default mapping of discriminator properties to the "$type" JSON property name.

  • Adds HasColumnType() method support for complex properties and collections mapped to JSON
  • Maps discriminator properties to "$type" JSON property name by default
  • Consolidates container column functionality from separate entity/complex type extensions into a unified TypeBase extension

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs Adds unified container column name/type methods for all type bases
src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs Updates default JSON property name to use "$type" for discriminator properties
src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs Removes container column methods (moved to TypeBase)
src/EFCore.Relational/Extensions/RelationalComplexTypeExtensions.cs File deleted (functionality moved to TypeBase)
src/EFCore.Relational/Extensions/RelationalComplexPropertyBuilderExtensions.cs Adds HasColumnType() method for complex properties
src/EFCore.Relational/Extensions/RelationalComplexCollectionBuilderExtensions.cs Adds HasColumnType() method for complex collections
test/EFCore.Relational.Tests/TestUtilities/TestRelationalTypeMappingSource.cs Adds test JSON mapping support
test/EFCore.Relational.Tests/RelationalApiConsistencyTest.cs Updates API consistency test references
test/EFCore.Relational.Tests/Metadata/RelationalModelTest.cs Adds tests for container column type functionality
test/EFCore.Relational.Specification.Tests/ModelBuilding/RelationalTestModelBuilderExtensions.cs Adds test builder extensions for HasColumnType()
test/EFCore.Relational.Specification.Tests/ModelBuilding/RelationalModelBuilderTest.cs Adds comprehensive tests for new functionality
Comments suppressed due to low confidence (1)

src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs:419

  • The variable name 'columnName' is misleading since it represents a column type, not a column name. It should be renamed to 'columnType' for clarity.
     => typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnType)?.Value is string columnName

@AndriySvyryd AndriySvyryd merged commit ce56d77 into main Aug 1, 2025
7 checks passed
@AndriySvyryd AndriySvyryd deleted the Issue31252_JsonType branch August 1, 2025 15:34
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.

Add relational JSON mapping support for complex types

2 participants