Querying a TPC base type with a JSON complex property throws

Aperta
#39,814 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@cincuranet ci sta già lavorando.

Dal 26/11/2026.

  • #39815 di @jeremy-morren — aperta
  • #39834 di @jeremy-morren — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
22/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp, json, sql
Ambito
databases

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area-query

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.

Lingua principale
C#
Stelle
14.8k
Fork
3.5k
Merge medio
3g 7h
PR unite (30g)
182

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotnet/efcore

Tutte le issue di dotnet/efcore

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.