From 20b88248e9b342ebe4f58b53a0a58e5deebc9854 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Wed, 19 Jun 2024 15:10:11 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=20.Contains('b%')=20?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=95=B0=E6=8D=AE=E5=BA=93=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BD=8D=E7=BD=AE=E9=94=99=E8=AF=AF=EF=BC=9B?= =?UTF-8?q?#1826?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs | 2 +- .../Oracle/CustomOracleExpression.cs | 6 +++--- .../PostgreSQL/CustomPostgreSQLExpression.cs | 6 +++--- .../SqlServer/CustomSqlServerExpression.cs | 2 +- Providers/FreeSql.Provider.Dameng/DamengExpression.cs | 6 +++--- Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs | 2 +- Providers/FreeSql.Provider.GBase/GBaseExpression.cs | 2 +- .../FreeSql.Provider.KingbaseES/KingbaseESExpression.cs | 6 +++--- Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs | 6 +++--- Providers/FreeSql.Provider.MySql/MySqlExpression.cs | 2 +- .../FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs | 6 +++--- .../KingbaseES/OdbcKingbaseESExpression.cs | 6 +++--- .../FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs | 2 +- .../FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs | 6 +++--- .../PostgreSQL/OdbcPostgreSQLExpression.cs | 6 +++--- .../SqlServer/OdbcSqlServerExpression.cs | 2 +- Providers/FreeSql.Provider.Oracle/OracleExpression.cs | 6 +++--- .../FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs | 6 +++--- Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs | 7 +++---- Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs | 6 +++--- .../FreeSql.Provider.SqlServer/SqlServerExpression.cs | 2 +- Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs | 6 +++--- Providers/FreeSql.Provider.Xugu/XuguExpression.cs | 6 +++--- 23 files changed, 53 insertions(+), 54 deletions(-) diff --git a/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs b/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs index f02bac5c8..fee89ee6f 100644 --- a/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs +++ b/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs @@ -316,7 +316,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({args0Value})"; + if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"locate({args0Value}, {left}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; diff --git a/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs b/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs index 0bef32718..17c95218c 100644 --- a/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs +++ b/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})"; - return $"instr({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; + if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; + return $"instr({left}, {args0Value}, 1, 1) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; diff --git a/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs b/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs index 2af3ba6ef..5e010701e 100644 --- a/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs +++ b/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs @@ -407,9 +407,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})"; - return $"strpos({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1"; + return $"strpos({left}, {args0Value}) > 0"; } var likeOpt = "LIKE"; if (exp.Arguments.Count > 1) diff --git a/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs b/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs index 37b7e4bea..bf1239101 100644 --- a/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs +++ b/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs @@ -339,7 +339,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({args0Value})"; + if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1"; return $"charindex({args0Value}, {left}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}"; diff --git a/Providers/FreeSql.Provider.Dameng/DamengExpression.cs b/Providers/FreeSql.Provider.Dameng/DamengExpression.cs index 5a79dd501..e50d495c6 100644 --- a/Providers/FreeSql.Provider.Dameng/DamengExpression.cs +++ b/Providers/FreeSql.Provider.Dameng/DamengExpression.cs @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})"; - return $"instr({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; + if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; + return $"instr({left}, {args0Value}, 1, 1) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; diff --git a/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs b/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs index a652284e0..41748e515 100644 --- a/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs +++ b/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs @@ -306,7 +306,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"position({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"position({args0Value}, {left}) = char_length({args0Value})"; + if (exp.Method.Name == "EndsWith") return $"position({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"position({args0Value}, {left}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}"; diff --git a/Providers/FreeSql.Provider.GBase/GBaseExpression.cs b/Providers/FreeSql.Provider.GBase/GBaseExpression.cs index d848dd3c4..ca4000fb7 100644 --- a/Providers/FreeSql.Provider.GBase/GBaseExpression.cs +++ b/Providers/FreeSql.Provider.GBase/GBaseExpression.cs @@ -306,7 +306,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = char_length({args0Value})"; + if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"instr({args0Value}, {left}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}"; diff --git a/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs b/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs index 1f121e3f1..dee12a3de 100644 --- a/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs +++ b/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs @@ -385,9 +385,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})"; - return $"strpos({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1"; + return $"strpos({left}, {args0Value}) > 0"; } var likeOpt = "LIKE"; if (exp.Arguments.Count > 1) diff --git a/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs b/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs index fb7a0dae6..6f9824186 100644 --- a/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs +++ b/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs @@ -279,9 +279,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = len({args0Value})"; - return $"instr({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}) = len({left})-len({args0Value})+1"; + return $"instr({left}, {args0Value}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value}+'%')")}"; if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+{args0Value})")}"; diff --git a/Providers/FreeSql.Provider.MySql/MySqlExpression.cs b/Providers/FreeSql.Provider.MySql/MySqlExpression.cs index c5a034411..9ae5b7afe 100644 --- a/Providers/FreeSql.Provider.MySql/MySqlExpression.cs +++ b/Providers/FreeSql.Provider.MySql/MySqlExpression.cs @@ -318,7 +318,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({args0Value})"; + if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"locate({args0Value}, {left}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs index 130457224..a1b7f3ffa 100644 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})"; - return $"instr({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; + if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; + return $"instr({left}, {args0Value}, 1, 1) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs index 41e97391f..b5d7e5c3a 100644 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs @@ -385,9 +385,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})"; - return $"strpos({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1"; + return $"strpos({left}, {args0Value}) > 0"; } var likeOpt = "LIKE"; if (exp.Arguments.Count > 1) diff --git a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs index dc0a7b01b..34710f938 100644 --- a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs @@ -316,7 +316,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({args0Value})"; + if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"locate({args0Value}, {left}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; diff --git a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs index 665ead9a5..333ea5984 100644 --- a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})"; - return $"instr({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; + if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; + return $"instr({left}, {args0Value}, 1, 1) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; diff --git a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs index 086f9ff8f..3367d1028 100644 --- a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs @@ -407,9 +407,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})"; - return $"strpos({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1"; + return $"strpos({left}, {args0Value}) > 0"; } var likeOpt = "LIKE"; if (exp.Arguments.Count > 1) diff --git a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs index eea094838..abe8b4b54 100644 --- a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs @@ -339,7 +339,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({args0Value})"; + if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1"; return $"charindex({args0Value}, {left}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}"; diff --git a/Providers/FreeSql.Provider.Oracle/OracleExpression.cs b/Providers/FreeSql.Provider.Oracle/OracleExpression.cs index 7fe6a51ae..c96e20f9e 100644 --- a/Providers/FreeSql.Provider.Oracle/OracleExpression.cs +++ b/Providers/FreeSql.Provider.Oracle/OracleExpression.cs @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})"; - return $"instr({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; + if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; + return $"instr({left}, {args0Value}, 1, 1) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; diff --git a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs index f3d28da35..045707271 100644 --- a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs +++ b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs @@ -438,9 +438,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})"; - return $"strpos({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1"; + return $"strpos({left}, {args0Value}) > 0"; } var likeOpt = "LIKE"; if (exp.Arguments.Count > 1) diff --git a/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs b/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs index 41b5df010..3d2a06174 100644 --- a/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs +++ b/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs @@ -345,10 +345,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") - return $"strpos({args0Value}, {left}) = length({args0Value})"; - return $"strpos({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = length({left})-length({args0Value})+1"; + return $"strpos({left}, {args0Value}) > 0"; } var likeOpt = "LIKE"; diff --git a/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs b/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs index 2bd58df38..62754aff7 100644 --- a/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs +++ b/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs @@ -362,9 +362,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})"; - return $"strpos({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1"; + return $"strpos({left}, {args0Value}) > 0"; } var likeOpt = "LIKE"; if (exp.Arguments.Count > 1) diff --git a/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs b/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs index 3d3b6a95e..694e03f8f 100644 --- a/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs +++ b/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs @@ -338,7 +338,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({args0Value})"; + if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1"; return $"charindex({args0Value}, {left}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}"; diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs b/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs index 7a4b2b68e..2f27449bd 100644 --- a/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs +++ b/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs @@ -314,9 +314,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})"; - return $"instr({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}) = length({left})-length({args0Value})+1"; + return $"instr({left}, {args0Value}) > 0"; } if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}"; if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"'%'||({args0Value})")}"; diff --git a/Providers/FreeSql.Provider.Xugu/XuguExpression.cs b/Providers/FreeSql.Provider.Xugu/XuguExpression.cs index af28b515f..a703a9633 100644 --- a/Providers/FreeSql.Provider.Xugu/XuguExpression.cs +++ b/Providers/FreeSql.Provider.Xugu/XuguExpression.cs @@ -363,9 +363,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value.Contains("%")) { - if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})"; - return $"strpos({args0Value}, {left}) > 0"; + if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; + if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1"; + return $"strpos({left}, {args0Value}) > 0"; } var likeOpt = "LIKE"; if (exp.Arguments.Count > 1)