Browse Source

Add SqlFunc.SplitIn

pull/31/head
sunkaixuan 2 years ago
parent
commit
ee33b8e5da
  1. 32
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  2. 1
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs
  3. 5
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  4. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs

32
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<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){ IsMember=true, MemberName=fullString },
new MethodCallExpressionArgs(){ IsMember=true, MemberName=value1 }
} });
var likeString2 =
EndsWith(new MethodCallExpressionModel()
{
Args = new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){ IsMember=true, MemberName=fullString },
new MethodCallExpressionArgs(){ IsMember=true, MemberName=value2 }
}
});
var likeString3 =
Contains(new MethodCallExpressionModel()
{
Args = new List<MethodCallExpressionArgs>() {
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}";

1
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);
}
}

5
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");
}
}
}

2
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;
}

Loading…
Cancel
Save