Support complex properties on owned types in JSON-mapped owned collections

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

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

Chưa có ai nhận issue này.

Đá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
52/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp

Hướng nghiên cứu

Start by reading the discussion on PR #39522, which this issue says must merge first, then trace EF Core's model validation for complex properties mapped inside JSON owned collections. Check the tests for JSON-mapped owned collections and nested owned types. Done means complex properties work for the described nesting patterns and the model validation error no longer blocks them.

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

Mô tả

area-complex-types area-owned-entities

Follow up to #39522. Filing this issue now to include the id as a comment, not relevant until that PR is merged.

public class Order
{
    public int Id { get; set; }
    public List<OrderLine> Lines { get; set; } = [];
}

public class OrderLine
{
    public string Sku { get; set; }
    public Money Price { get; set; }
}

public class Money
{
    public decimal Amount { get; set; }
    public string Currency { get; set; }
}
modelBuilder.Entity<Order>().OwnsMany(
    o => o.Lines, b =>
    {
        b.ToJson();
        b.ComplexProperty(l => l.Price);
    });

Expected: Price is stored in each element of the Lines JSON array, as it is for OwnsOne(...).ToJson().

Actual: model validation throws:

Complex property 'OrderLine.Price' cannot be declared on 'OrderLine', which is mapped to JSON as part of an owned collection. Complex properties on owned types in JSON collections aren't supported; map the collection with 'ComplexCollection(...).ToJson()' instead.

The same applies to any owned type below a JSON owned collection: an OwnsOne nested in OwnsMany(...).ToJson(), and an OwnsMany nested in OwnsOne(...).ToJson().

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.