From 49c997dd3f4b61cd514c8e0a24f0373dc5bbecd2 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 23 Apr 2020 17:08:24 +0200 Subject: [PATCH] Fix StartsWith on Sqlite (#20716) For non-constant patterns Fixes #20715 --- .../Query/Internal/SqliteStringMethodTranslator.cs | 2 +- .../Query/NorthwindQueryFiltersQuerySqliteTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs index 47fb1fd9156..321465faef0 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs @@ -264,7 +264,7 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress _sqlExpressionFactory.Like( instance, _sqlExpressionFactory.Add( - instance, + pattern, _sqlExpressionFactory.Constant("%"))), _sqlExpressionFactory.Equal( _sqlExpressionFactory.Function( diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQueryFiltersQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQueryFiltersQuerySqliteTest.cs index d1e0bff68e6..8c9604e7161 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQueryFiltersQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQueryFiltersQuerySqliteTest.cs @@ -23,7 +23,7 @@ public override void Count_query() SELECT COUNT(*) FROM ""Customers"" AS ""c"" -WHERE (@__ef_filter__TenantPrefix_0 = '') OR (""c"".""CompanyName"" IS NOT NULL AND (((""c"".""CompanyName"" LIKE ""c"".""CompanyName"" || '%') AND (substr(""c"".""CompanyName"", 1, length(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0)) OR (@__ef_filter__TenantPrefix_0 = '')))"); +WHERE (@__ef_filter__TenantPrefix_0 = '') OR (""c"".""CompanyName"" IS NOT NULL AND (((""c"".""CompanyName"" LIKE @__ef_filter__TenantPrefix_0 || '%') AND (substr(""c"".""CompanyName"", 1, length(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0)) OR (@__ef_filter__TenantPrefix_0 = '')))"); } private void AssertSql(params string[] expected)