Repository navigation
Escape the LIKE escape character for char parameters in StartsWith/EndsWith/Contains - #39316
Merged
AndriySvyryd merged 1 commit intoOct 21, 2026
Merged
Conversation
…dsWith/Contains For a char parameter, SQL Server and SQLite build the LIKE pattern at runtime and always add ESCAPE '\', but only the wildcard characters were escaped, not the escape character itself. With a backslash parameter, StartsWith produced '\%' (matches only the string "%"), EndsWith produced '%\' (a dangling escape that matches nothing) and SQL Server's Contains produced '%\%%' (matches any string containing '%'). String parameters were already escaped correctly.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed changes address the reported escaping issue and include shared regression coverage with provider-specific baselines.
No open issues 🎉
What changed in this PR
This pull request fixes LIKE pattern construction for backslash character parameters in SQL Server and SQLite StartsWith, EndsWith, and Contains translations.
Changes:
- Escape the
LIKEescape character in runtime patterns. - Add shared regression coverage for all three string operations.
- Add SQL Server and SQLite baseline assertions.
| File | Description |
|---|---|
test/EFCore.SqlServer.FunctionalTests/Query/FunkyDataQuerySqlServerTest.cs |
Adds SQL Server baselines for corrected runtime patterns. |
test/EFCore.Sqlite.FunctionalTests/Query/FunkyDataQuerySqliteTest.cs |
Adds SQLite baselines for corrected runtime patterns. |
test/EFCore.Specification.Tests/Query/FunkyDataQueryTestBase.cs |
Adds shared regression tests for backslash character parameters. |
src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitor.cs |
Escapes backslash character parameters in SQL Server LIKE patterns. |
src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitor.cs |
Escapes backslash character parameters in SQLite LIKE patterns. |
Review effort: Lite
AndriySvyryd
approved these changes
Oct 21, 2026
Member
|
Thanks for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For a char parameter, SQL Server and SQLite build the LIKE pattern at runtime and always add ESCAPE '', but only the wildcard characters were escaped, not the escape character itself. With a backslash parameter, StartsWith produced '%' (matches only the string "%"), EndsWith produced '%' (a dangling escape that matches nothing) and SQL Server's Contains produced '%%%' (matches any string containing '%'). String parameters were already escaped correctly.