Browse Source

Synchronization code

pull/40/head
sunkaixuan 1 year ago
parent
commit
e61c9712d4
  1. 39
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  2. 8
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs

39
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -562,7 +562,18 @@ namespace SqlSugar
{
var str = model.Args[0].MemberValue.ObjToString();
var array = model.Args.Skip(1).Select(it => it.IsMember ? it.MemberName : it.MemberValue).ToArray();
return string.Format("'" + str + "'", array);
if (array.Length == 1 && array[0] is string[])
{
List<MethodCallExpressionArgs> args = GetStringFormatArgs(str, array[0] as string[]);
return Format(new MethodCallExpressionModel()
{
Args = args
}); ;
}
else
{
return string.Format("'" + str + "'", array);
}
}
public virtual string Format(MethodCallExpressionModel model)
{
@ -573,6 +584,14 @@ namespace SqlSugar
{
return FormatConcat(model);
}
if (model.Args.Count == 2 && model.Args[1].MemberValue is string[])
{
List<MethodCallExpressionArgs> args = GetStringFormatArgs(str, model.Args[1].MemberValue as string[]);
return Format(new MethodCallExpressionModel()
{
Args = args
}); ;
}
str =Regex.Replace(str, @"(\{\d+?\})", revalue);
var array = model.Args.Skip(1).Select(it => it.IsMember?it.MemberName:(it.MemberValue==null?"''":it.MemberValue.ToSqlValue()))
.Select(it=>ToString(new MethodCallExpressionModel() { Args=new List<MethodCallExpressionArgs>() {
@ -969,6 +988,24 @@ namespace SqlSugar
}
}
private static List<MethodCallExpressionArgs> GetStringFormatArgs(string str, object array)
{
var args = new List<MethodCallExpressionArgs>()
{
new MethodCallExpressionArgs(){
MemberName=str,
MemberValue=str
}
};
args.AddRange((array as string[]).Select(it => new MethodCallExpressionArgs()
{
MemberValue = it,
MemberName = it
}));
return args;
}
public virtual string WeekOfYear(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;

8
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs

@ -366,6 +366,14 @@ namespace SqlSugar
{
parameter.CommonTempData = GetNewExpressionValue(item);
}
else if (name == "Format" && item is NewArrayExpression)
{
var exps = (item as NewArrayExpression).Expressions;
parameter.CommonTempData = exps.Select(it => {
var res = GetNewExpressionValue(ExpressionTool.RemoveConvert(it));
return res;
}).ToArray();
}
else
{
base.Start();

Loading…
Cancel
Save