Conversation
When string.StartsWith(char) is called with a LIKE wildcard ('%', '_' or '['),
the SQL Server translator built the pattern with `LikeEscapeChar + s + "%"`.
Both operands of the first `+` are chars, so they are added numerically and the
pattern becomes e.g. `LIKE N'129%'` instead of `LIKE N'\%%' ESCAPE N'\'`. The
query runs but matches the wrong rows. EndsWith and Contains were already
concatenating correctly.
Use string interpolation for both the constant and the parameter path, and add
FunkyData tests covering the constant, parameter, bracket and negated cases.
Fixes dotnet#38923
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
The 7 failures are all in |
| methodType switch | ||
| { | ||
| StartsEndsWithContains.StartsWith => LikeEscapeChar + s + "%", | ||
| StartsEndsWithContains.StartsWith => $"{LikeEscapeChar}{s}%", |
There was a problem hiding this comment.
Also change this for EndsWith and for any other ambiguous use of the + operator with a char
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The constant wildcard path still emits unsupported ESCAPE SQL on Azure Synapse.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Fixes SQL Server StartsWith(char) translation for LIKE wildcard characters and adds regression coverage.
Changes:
- Corrects constant and parameterized pattern construction.
- Adds shared wildcard and negated-case tests.
- Adds SQL Server SQL baselines.
| File | Summary |
|---|---|
test/EFCore.SqlServer.FunctionalTests/Query/FunkyDataQuerySqlServerTest.cs |
Adds SQL Server baselines. |
test/EFCore.Specification.Tests/Query/FunkyDataQueryTestBase.cs |
Adds shared regression tests. |
src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitor.cs |
Fixes wildcard pattern construction. |
…cards on Azure Synapse Rewrite every StartsWith/EndsWith/Contains LIKE pattern arm in the SQL Server and SQLite translators as an interpolated string, so no arm relies on operand order to keep a char from being added numerically. On Azure Synapse the constant char wildcard case still emitted LIKE ... ESCAPE, which Synapse does not support. Route it through TranslateWithoutLike like the string constant and parameter cases already do, passing a string constant so the LEFT/RIGHT/CHARINDEX translation does not render a char-valued constant with a string type mapping. Add Synapse baselines for the char wildcard tests. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>


When string.StartsWith(char) is called with a LIKE wildcard ('%', '_' or '['), the SQL Server translator built the pattern with
LikeEscapeChar + s + "%". Both operands of the first+are chars, so they are added numerically and the pattern becomes e.g.LIKE N'129%'instead ofLIKE N'\%%' ESCAPE N'\'. The query runs but matches the wrong rows. EndsWith and Contains were already concatenating correctly.Use string interpolation for both the constant and the parameter path, and add FunkyData tests covering the constant, parameter, bracket and negated cases.
Fixes #38923