Query precompilation is all-or-nothing per project; allow writing the interceptors of the queries that did precompile

Đang mở
#39,540 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
48/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
Lĩnh vực
backend, tooling

Hướng nghiên cứu

Start with DbContextOperations.PrecompileQueries and PrecompiledQueryCodeGenerator.ProcessSyntaxTree, the two entry points named in the issue. Trace how generation errors are collected and how per-query state is written, then inspect the precompilation tests and the documented non-NativeAOT behavior. Done means an opt-in can write interceptors for successful queries, report failures, and avoid leaving partial query regions when generation fails.

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

Mô tả

area-precompiled-queries area-tools

DbContextOperations.PrecompileQueries throws if precompilationErrors.Count > 0, so one query that cannot be precompiled discards the interceptors of every other query in the project. The docs ("Precompiled queries without NativeAOT") say the command "will generate a compiled model and interceptors for queries which could be precompiled", which is not what 10.0.11 does.

In a real application (SentenceStudio: ~600 queries, 4 projects) this means no project gets any interceptors until the last query is rewritten. With EF Core 10.0.11 plus the precompiler fixes now on main, 394 queries precompile and 202 do not; the stock tool writes 0 of the 394.

A second, smaller problem blocks a simple "continue on error": PrecompiledQueryCodeGenerator.ProcessSyntaxTree appends to the file's _code, _namespaces and _unsafeAccessors while it generates a query. If generation throws after #region QueryN was written, the catch records the error and continues, leaving that half-written region in the file.

What we did locally (design-time only) to measure the rest of the app:

  1. In ProcessSyntaxTree, snapshot _code, _namespaces and _unsafeAccessors before each query and restore them in the catch.
  2. In DbContextOperations.PrecompileQueries, an opt-in that reports the errors as warnings and writes the files.

Ask: an option (for example --allow-partial / <EFPrecompileQueriesAllowPartial>) that writes the precompilable queries and reports the rest, at least when not publishing NativeAOT. Under NativeAOT the remaining queries still throw "Query wasn't precompiled", so the option is most useful for (a) the non-AOT startup benefit the docs describe and (b) incremental migration of a large codebase to NativeAOT.

Versions: EF Core 10.0.11, .NET SDK 11.0.100-rc.2.

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.