diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs index d70f8e854..58ded39fc 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs @@ -689,12 +689,42 @@ namespace SqlSugar { throw new NotImplementedException("Current database no support"); } - public string CompareTo(MethodCallExpressionModel model) + public virtual string CompareTo(MethodCallExpressionModel model) { var parameterNameA=model.Args[0].MemberName; var parameterNameB = model.Args[1].MemberName; return $"(case when {parameterNameA}>{parameterNameB} then 1 when {parameterNameA}={parameterNameB} then 0 else -1 end)"; } + public virtual string SplitIn(MethodCallExpressionModel model) + { + var fullString = model.Args[0].MemberName+""; + var value = model.Args[1].MemberName+""; + var value1 = MergeString(value, "','"); + var value2 = MergeString("','", value); + var value3 = MergeString("','", value, "','"); + var likeString1 = + StartsWith(new MethodCallExpressionModel() { Args = new List() { + new MethodCallExpressionArgs(){ IsMember=true, MemberName=fullString }, + new MethodCallExpressionArgs(){ IsMember=true, MemberName=value1 } + } }); + var likeString2 = + EndsWith(new MethodCallExpressionModel() + { + Args = new List() { + new MethodCallExpressionArgs(){ IsMember=true, MemberName=fullString }, + new MethodCallExpressionArgs(){ IsMember=true, MemberName=value2 } + } + }); + var likeString3 = + Contains(new MethodCallExpressionModel() + { + Args = new List() { + new MethodCallExpressionArgs(){ IsMember=true, MemberName=fullString }, + new MethodCallExpressionArgs(){ IsMember=true, MemberName=value3 } + } + }); + return $" ({likeString1} or {likeString2} or {likeString3}) "; + } public virtual string GetTableWithDataBase(string dataBaseName,string tableName) { return $"{dataBaseName}.{tableName}"; diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs index f0c947e00..7f87049fa 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs @@ -103,6 +103,7 @@ namespace SqlSugar string JsonListObjectAny(MethodCallExpressionModel model); string JsonArrayAny(MethodCallExpressionModel model); string CompareTo(MethodCallExpressionModel model); + string SplitIn(MethodCallExpressionModel model); string GetTableWithDataBase(string databaseName,string tableName); } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs index a149d4018..299e14647 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs @@ -278,5 +278,10 @@ namespace SqlSugar { throw new NotSupportedException("Can only be used in expressions"); } + + public static bool SplitIn(string CommaSegmentationString, string inValue) + { + throw new NotSupportedException("Can only be used in expressions"); + } } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs index e702bc998..ae8b1817f 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs @@ -783,6 +783,8 @@ namespace SqlSugar return this.Context.DbMehtods.JsonArrayAny(model); case "CompareTo": return this.Context.DbMehtods.CompareTo(model); + case "SplitIn": + return this.Context.DbMehtods.SplitIn(model); default: break; }