Repository navigation
Allow changing CLR type without SQL conversion - #39397
Conversation
- Add a CLR type change SQL expression - Use it for string-converted enum ToString() Fixes dotnet#33733
There was a problem hiding this comment.
🟡 Changes recommended
Removing casts exposes SQL Server store-type mismatches and truncation regressions in composed string operations.
2 open issues
What changed in this PR
Adds a SQL expression that changes the exposed CLR type without emitting a SQL conversion, addressing #33733 for string-converted enums.
Changes:
- Introduces
ClrTypeChangeExpressionand integrates mapping, nullability, SQL generation, and parentheses handling. - Uses the new expression for enum
ToString()translation. - Updates API baselines and adds composed
ToString().Contains(...)coverage.
| File | Description |
|---|---|
test/EFCore.SqlServer.FunctionalTests/Query/AdHocMiscellaneousQuerySqlServerTest.cs |
Updates SQL Server baselines and adds the composed query baseline. |
test/EFCore.Sqlite.FunctionalTests/Query/AdHocMiscellaneousQuerySqliteTest.cs |
Updates SQLite baselines and adds the composed query baseline. |
test/EFCore.Relational.Specification.Tests/Query/AdHocMiscellaneousQueryRelationalTestBase.cs |
Adds shared result assertions for composed string operations. |
src/EFCore.Relational/Query/SqlNullabilityProcessor.cs |
Propagates operand nullability through the new expression. |
src/EFCore.Relational/Query/SqlExpressions/ClrTypeChangeExpression.cs |
Defines the CLR-only type-change expression. |
src/EFCore.Relational/Query/SqlExpressionFactory.cs |
Supports mapping the new expression. |
src/EFCore.Relational/Query/QuerySqlGenerator.cs |
Emits only the operand and handles parentheses. |
src/EFCore.Relational/Query/Internal/Translators/EnumMethodTranslator.cs |
Replaces string-converted enum casts with the new expression. |
src/EFCore.Relational/EFCore.Relational.baseline.json |
Records the added public and protected APIs. |
Review effort: Balanced
- Preserve converted enum store type mappings - Widen bounded Replace inputs when required - Add SQL Server regression coverage
There was a problem hiding this comment.
🟡 Changes recommended
The PR bundles an unrelated SQL Server REPLACE translation change, which widens bounded varchar inputs to varchar(max) and affects plain string columns, but the PR description covers only the enum CLR type change and the related tests are not yet explained or split out.
1 open issue
2 resolved since last review
Review effort: Lite
- Revert the EnumMethodTranslator and SqlServerStringMethodTranslator workarounds - Wrap stripped no-op CASTs in ClrTypeChangeExpression when the CLR type or mapping changes - Look through ClrTypeChangeExpression when deciding whether a projection alias is redundant - Rework SQL Server regression coverage for bounded string-converted enums
eb05099 to
338fbbe
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Human verification is warranted because the change introduces a public SQL-expression node and cross-provider SQL generation changes that could affect SQL Server CAST behavior and downstream visitors, while SQL Server execution was unavailable locally.
No open issues 🎉
1 resolved since last review
Review effort: Lite
AndriySvyryd
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
API review baseline changes for
|


Fixes #33733
This adds a dedicated
ClrTypeChangeExpressionwhich allows a SQL expression to expose a different CLR type without emitting a corresponding SQL conversion.EnumToStringConverter<>, avoiding unnecessary SQLCASTs forToString().ToString().Contains(...)case.Local validation:
./build.shEFCore.ApiBaseline.Tests: 14 passedEFCore.Relational.Tests: 1,525 passed, 1 skippedEFCore.Sqlite.FunctionalTests: 38,334 passed, 285 skippedSQL Server functional tests were not executed locally because the project skips tests on non-Windows environments when
Test__SqlServer__DefaultConnectionis not configured. The SQL Server test project and updated SQL baselines build successfully.