Querying a TPC base type with a JSON complex property throws
Maintainers usually reply within 2 days
@cincuranet is already working on this.
Since Nov 26, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
Research direction
The failure comes from GenerateJsonReader in ShaperProcessingExpressionVisitor, reached through ProcessTopLevelComplexJsonProperties; start by reading how it searches the query mappings of the abstract TPC base type. The issue suggests using the projection column from the UNION ALL instead. Done means the Set<Base>() query with a JSON complex property returns both rows, with a regression test covering it. A pull request (#39815) is already open against this issue, so check it first.
Written by the indexing model from the issue text.
Description
When a JSON complex property is declared on an abstract TPC base type, querying the base type throws while locating the JSON column.
public abstract class Base
{
public int Id { get; set; }
public required Document Document { get; set; }
}
public class First : Base;
public class Second : Base;
public class Document
{
public required string Value { get; set; }
}
modelBuilder.Entity<Base>(b =>
{
b.UseTpcMappingStrategy();
b.ComplexProperty(r => r.Document).ToJson();
});
modelBuilder.Entity<First>().ToTable("First");
modelBuilder.Entity<Second>().ToTable("Second");
context.AddRange(
new First { Id = 1, Document = new Document { Value = "A" } },
new Second { Id = 2, Document = new Document { Value = "B" } });
await context.SaveChangesAsync();
var rows = await context.Set<Base>().OrderBy(r => r.Id).ToListAsync();
Expected the two rows, actual:
System.Diagnostics.UnreachableException: Could not find JSON container column 'Document' for entity type 'Base.Document#Document'.
at ShaperProcessingExpressionVisitor.GenerateJsonReader(Int32 jsonColumnIndex, ITypeBase structuralType, IColumnBase jsonColumn)
at ShaperProcessingExpressionVisitor.ProcessTopLevelComplexJsonProperties(...)
GenerateJsonReader looks the column up in the query mappings of the abstract base type, which isn't mapped to a table with TPC. The column of the projection (from the UNION ALL over the concrete tables) is already known at that point and could be used instead.
Saving works.
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.5k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 182
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
customer-reported
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
GroupBy element `OrderBy(...).First()`/`MaxBy` over an owned type mapped to its own table fails to translatePossibly taken @cincuranet claimed this today. Openarea-groupby area-query
Difficulty 4/5 3-5 days Newbie friendliness 25/100
dotnet/efcore#39833 · 1 assignee ·
Maintainers usually reply within 2 days
-
SQLite: Polygon.Length translates to GLength, which returns 0Possibly taken @cincuranet claimed this today. Openarea-query area-sqlite
Difficulty 3/5 1-2 days Newbie friendliness 45/100
dotnet/efcore#39826 · 1 assignee ·
Maintainers usually reply within 2 days
-
Migration lock with LockReleaseBehavior.Transaction doesn't prevent concurrent migrations since per-migration transactionsPossibly taken @AndriySvyryd claimed this 1 day ago. Openarea-migrations
dotnet/efcore#39824 · 1 assignee ·
Maintainers usually reply within 2 days
-
Three Cosmos structural-equality tests flaky on Cosmos DB Emulator for WindowsPossibly taken @su-senka claimed this 1 day ago. Open
Difficulty 3/5 Half a day Newbie friendliness 35/100
dotnet/efcore#39809 · 1 comment ·
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
SubtitleEdit/subtitleedit#17247 ·
Maintainers usually reply within 1 day
-
Restore test cleanup fails on Windows when restored files are read-onlyPossibly taken @JamBalaya56562 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
duplicati/duplicati#8046 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Bundles Documentation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pyrevitlabs/pyRevit#4285 ·
Maintainers usually reply within 1 day