Reject member and method translations incompatible with the mapped store representation
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ó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with RelationalSqlTranslatingExpressionVisitor.cs and the provider translators named in the issue, then read the existing enum ToString translations and Boolean compensation to understand behavior that must be preserved. Trace how translation failures add diagnostic details and locate the provider test suites for member, method, predicate, and set-based update/delete translation. Done means incompatible converted representations fail during translation with actionable diagnostics while the listed valid translations and top-level client projections continue to work.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Split from #10434.
A mapped property's CLR type does not necessarily describe its database representation. A value converter can store a DateTime as a binary-encoded integer, for example, while the translated column expression still has CLR type DateTime.
A translator that selects a database operation solely from the CLR member or method can consequently apply that operation to an incompatible representation. This can produce a database error or, more seriously, execute successfully with incorrect results. Incorrect predicates can also select the wrong rows for set-based updates or deletes. The latter is a risk motivating this work, not a reproduced data-corruption report.
Until conversion-aware translation is implemented in #10434, EF should reject translations whose required store representation is incompatible and explain why, rather than generate misleading SQL or leave the database to report an unrelated error.
Describe the solution you'd like
Validate representation compatibility when translating members and methods, including operations whose relevant operand is an argument rather than the instance.
When a translation requires a representation that the mapped operand does not have, decline that translation and add a specific translation-error detail identifying:
- The member or method that could not be translated.
- The model CLR type and actual store type/provider representation, and the affected property when available.
- That the operation cannot be translated safely with this mapping/value conversion.
- Actionable alternatives: use a compatible mapping, provide a conversion-aware provider translation, or explicitly evaluate the operation on the client where appropriate.
Follow the normal query translation failure path. Do not silently introduce client evaluation in predicates or other server-required positions. Preserve existing permitted top-level client projection behavior.
This is not a blanket ban on value-converted operands, nor a requirement that store type names match exactly. Compatibility is operation- and provider-specific. Known valid converter-aware translations and legitimate store-type variants must continue to work. Converters that preserve the provider CLR type can still change semantics; provider/model CLR-type equality alone is not proof of compatibility.
Existing implementation checked
Static inspection of the current source found partial handling, but not a general member/method representation-compatibility guard:
- RelationalSqlTranslatingExpressionVisitor translates scalar instances/arguments and delegates to the member/method translator providers. Those dispatch paths do not generally reject operands because a converter changes their stored representation.
- SqlServerDateTimeMemberTranslator selects operations such as
DateTime.Yearfrom the declaring type/member and emitsDATEPARTwithout checking that the instance has a compatible temporal store representation. Some other members, such asDateTimeOffset.DateTime, already require a specific store type. - SqlServerDateTimeMethodTranslator similarly translates date-add methods without a general check of the instance's representation.
- EnumMethodTranslator already implements alternate
ToStringtranslations for recognized enum-to-number and enum-to-string converters. These are valid translations to preserve, not cases to reject. - RelationalValueConverterCompensatingExpressionVisitor compensates for converted Boolean predicates; it is not a general member/method guard.
- RelationalTypeMappingPostprocessor checks missing/conflicting type mappings in its supported contexts. Having a mapping does not establish that a particular operation is valid over that representation.
These observations are based on source inspection, not an executed reproduction. No specific database exception or wrong result is asserted here.
Acceptance criteria
- Cover member access and method calls on operands whose converters change their representation, including nullable operands and relevant static-method arguments.
- Include a temporal case such as a
DateTimestored usingToBinary/FromBinary, exercising both a member such asYearand a method such asAddDaysin server-required positions. - Confirm rejection happens during translation, before a database command is executed, and that the diagnostic explains the incompatible mapping.
- Cover predicates and supported set-based update/delete query paths so incompatible translations cannot determine affected rows or assigned values.
- Preserve ordinary translations without conversion, valid store-type variants, existing Boolean compensation, known enum
ToStringtranslations, and safe provider-specific/converter-aware translations. - Verify existing top-level client projection behavior is preserved.
- Put user-facing diagnostics in the owning project's resources and add provider-specific tests for the affected translation paths.
Scope and related work
- #10434 is the broader feature for conversion-aware/custom member and method translations. This issue provides fail-fast protection and diagnostics without waiting for that feature.
- #15979 concerns conversion metadata and operations such as comparisons and ordering; a general ordering-preservation design is not part of this issue.
- Alternative translations already supported by a provider should remain usable. Adding arbitrary new alternate translations is not required to complete this protection.
- Ngôn ngữ chính
- C#
- Star
- 14.8k
- Fork
- 3.5k
- Merge trung bình
- 2 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 158
Chuẩn bị môi trường
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.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc 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.
Issue khác của dotnet/efcore
-
Test bug: Include_collection_with_cross_apply_with_filter relies on nondeterministic ORDER BY with TakeCó thể đã có người làm @Mohamedadel-prog đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
dotnet/efcore#39848 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
customer-reported
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Compiled model: generate a deterministic model IDCó thể đã có người làm @rgroenewoudt đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 2 ngày
-
customer-reported
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của dotnet/efcore
Issue tương tự
-
area-VM-meta-mono untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/sqltoolsservice#2851 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
elsa-workflows/elsa-foundation#6322 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
mohebifar/made-in-iran#273 ·