Fix duplicate JSON column in TPT child tables for complex types declared on base entity type#37958
Draft
Fix duplicate JSON column in TPT child tables for complex types declared on base entity type#37958
Conversation
…red on base entity type When a complex property is mapped to JSON on a base entity type in a TPT hierarchy, the JSON column was being incorrectly created in child tables in addition to the base table. This is because `GetComplexProperties()` returns inherited properties, and there was no equivalent of the `GetColumnName(mappedTable) == null` filter used for scalar properties. The fix adds a check in `CreateTableMapping` to skip complex properties declared on base entity types that map to a different table (TPT scenario). TPC is excluded from this check since each TPC concrete table needs all properties including inherited ones. Fixes #38535 (Complex types and JSON Columns on Entity Types with TPT creates Duplicate JSON Column in Child Table) Co-authored-by: roji <1862641+roji@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix duplicate JSON column in child table for TPT
Fix duplicate JSON column in TPT child tables for complex types declared on base entity type
Mar 19, 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.
In TPT inheritance, a complex property configured with
.ToJson()on a base entity type incorrectly produced a JSON column in every child table in addition to the base table — causing duplicate schema and redundant data writes on insert.Root cause
RelationalModel.CreateTableMapping()iteratedmappedType.GetComplexProperties(), which returns inherited properties. Scalar properties are filtered byGetColumnName(mappedTable) == null, but no equivalent filter existed for JSON-mapped complex properties, so the column was unconditionally created on every table in the hierarchy.Changes
RelationalModel.CreateTableMapping()— when processing complex properties for an entity type, skip any complex property whose declaring entity type maps to a different table (the base table in TPT). The check is bypassed for TPC, where each concrete table must contain all columns including inherited ones.RelationalModelTest— addedComplex_property_json_column_is_not_duplicated_in_TPT_child_tablesto assert the JSON column appears only in the base table for a TPT hierarchy.Original prompt
This section details on the original issue you should resolve
<issue_title>EF Core 11.0: Complex types and JSON Columns on Entity Types with TPT creates Duplicate JSON Column in Child Table</issue_title>
<issue_description>### Bug description
EF Core 11.0 introduced Complex types and JSON columns on entity types with TPT/TPC inheritance.
Expected
When using
TPT, a JSON column is created inChildTable in addition toParenttable.Actual
When using
TPT, a JSON column created only in theParenttable.Your code
Using EF Core 11,
Consider the following Db Context
Stack traces
Verbose output
EF Core version
11.0.0-preview.2.26159.112
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.NET 11
Operating system
Windows 11
IDE
Visual Studio 2026 Insiders [11605.296]</issue_description>
Comments on the Issue (you are @copilot in this section)
@roji # AI TriageThe below is an AI-generated analysis and may contain inaccuracies.
Classification
Type: Bug
Areas:
area-complex-types,area-model-buildingAnalysis
I was able to confirm a bug with complex types mapped to JSON via
.ToJson()on a base entity type using TPT inheritance. The JSON column is incorrectly duplicated in child tables.When running the reported scenario (tested on SQLite with EF 11.0 preview 2), the following table DDL is generated: