Querying a TPC base type with a JSON complex property throws

Abierto
#39,814 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 2 días

@cincuranet ya está trabajando en esto.

Desde el 26/11/2026.

  • #39815 de @jeremy-morren — abierto
  • #39834 de @jeremy-morren — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
22/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
csharp, json, sql
Área
databases

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C#
Estrellas
14.8k
Forks
3.5k
Merge medio
3 d 7 h
PR fusionados (30 d)
182

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dotnet/efcore

Todos los issues de dotnet/efcore

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.