Entities with JSON owned entities can't be queried out with FromSql
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 14.8k
- Fork
- 3.4k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
For an entity type that has JSON owned entities, the following fails:
var items = await context.Blogs.FromSql($"WITH query AS (SELECT * FROM Blogs) SELECT * FROM query").ToListAsync();
It seems like when applying the final projection, we compose an additional SELECT on top:
SELECT b.Id, b.Name, b.Owned
FROM WITH query AS (SELECT * FROM Blogs) SELECT * FROM query
... and this (correctly) causes a non-composable SQL failure. We should not need to compose this extra SELECT on top.
With the focus on complex types for mapping JSON in EF 10, owned entities are getting de-prioritized. Given that, and given that we haven't seen many reports, i'll put this on the backlog for now.
Repro
await using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
var items = await context.Blogs.FromSql($"WITH query AS (SELECT * FROM Blogs) SELECT * FROM query").ToListAsync();
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer("Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>().OwnsOne(b => b.Owned).ToJson();
}
}
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }
public Owned Owned { get; set; }
}
public class Owned
{
public int OwnedProperty { get; set; }
}
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện BlogContext được cung cấp với SQL Server và kiểm tra SQL được tạo ra cho truy vấn FromSql liên quan đến thực thể owned JSON. Công việc hoàn tất khi truy vấn CTE non-composable này có thể được materialize mà không cần projection SELECT bên ngoài bổ sung.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp, sql
- Lĩnh vực
- database
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100