Querying a TPC base type with a JSON complex property throws

Đang mở
#39,814 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@cincuranet đang làm issue này rồi.

Từ ngày 26/11/2026.

  • #39815 của @jeremy-morren — đang mở
  • #39834 của @jeremy-morren — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
22/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp, json, sql
Lĩnh vực
databases

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C#
Star
14.8k
Fork
3.5k
Merge trung bình
3 ngày 7 giờ
Pull request đã merge (30 ngày)
182

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/efcore

Tất cả issue của dotnet/efcore

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.