Browse Source

Update exp to sql (string.format)

pull/40/head
sunkaixuan 1 year ago
parent
commit
b382d5ca4b
  1. 11
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  2. 8
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs

11
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -562,8 +562,15 @@ namespace SqlSugar
{
var str = model.Args[0].MemberValue.ObjToString();
var array = model.Args.Skip(1).Select(it => it.IsMember ? it.MemberName : it.MemberValue).ToArray();
if (array.Length == 1 && array[0] is string[])
{
return string.Format("'" + str + "'", array[0] as string[]);
}
else
{
return string.Format("'" + str + "'", array);
}
}
public virtual string Format(MethodCallExpressionModel model)
{
@ -573,6 +580,10 @@ namespace SqlSugar
{
return FormatConcat(model);
}
if (model.Args.Count == 2 && model.Args[1].MemberValue is string[])
{
return string.Format("" + str + "", model.Args[1].MemberValue as string[]);
}
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>() {

8
Src/Asp.NetCore2/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