Skip to content

Fix regression to allow LIKE translation for string comparison queries with non-constant args#387

Open
po-gl wants to merge 1 commit into
microting:masterfrom
po-gl:fix/issue386/like-string-comparisons
Open

Fix regression to allow LIKE translation for string comparison queries with non-constant args#387
po-gl wants to merge 1 commit into
microting:masterfrom
po-gl:fix/issue386/like-string-comparisons

Conversation

@po-gl

@po-gl po-gl commented Jun 18, 2026

Copy link
Copy Markdown

Closes #386

Resolves regression introduced during the upgrade to .NET 10 (4ac27f6)

In EF Core 9, the .Name property on SqlParameterExpression was prefixed with "__", i.e. QueryCompilationContext.QueryParameterPrefix. In EF Core 10, the prefix was removed as they were no longer needed to distinguish between parameter types (dedicated types were introduced). The prefix was not replaced with "@" or any other symbol, thus the existing guard in GetLikeExpressionUsingParameter will always fail. Similar guard statements were removed in EF Core 10 for the first party Sql server and Sqlite EFCore implementations.

Removing the guard allows the translator to use LIKE expressions for StartsWith, EndsWith, and Contains methods with non-constant arguments. For example, the following query (excerpt from repro code in issue):

await context.Widgets.Where(x => x.Name.StartsWith(pattern)).FirstOrDefaultAsync();

will translate to the following SQL with the changes from this PR:

SELECT `w`.`Id`, `w`.`Name`
FROM `Widgets` AS `w`
WHERE `w`.`Name` LIKE @pattern_startswith
LIMIT 1

- affects translations for StartsWith, EndsWith, and Contains methods
- regression introduced in 4ac27f6
- adds tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query translation regression for string comparison methods (StartsWith/EndsWith/Contains)

1 participant