diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs index 96d56bdba..9dfae4bc6 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace SqlSugar { @@ -510,8 +511,14 @@ namespace SqlSugar public virtual string Format(MethodCallExpressionModel model) { - var str = model.Args[0].MemberValue.ObjToString(); - var array = model.Args.Skip(1).Select(it => it.IsMember?it.MemberName:it.MemberValue).ToArray(); + + var str ="'"+ model.Args[0].MemberValue.ObjToString()+"'"; + var revalue = MergeString("'", "$1", "'"); + str =Regex.Replace(str, @"(\{\d+?\})", revalue); + var array = model.Args.Skip(1).Select(it => it.IsMember?it.MemberName:it.MemberValue) + .Select(it=>ToString(new MethodCallExpressionModel() { Args=new List() { + new MethodCallExpressionArgs(){ IsMember=true, MemberName=it } + } })).ToArray(); return string.Format(""+str+ "", array); } diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs index b8aac2339..a2f91f704 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; + namespace SqlSugar { public class MySqlExpressionContext : ExpressionContext, ILambdaExpressions @@ -66,7 +69,20 @@ namespace SqlSugar var parameter2 = model.Args[1]; return string.Format(" (TIMESTAMPDIFF(day,date({0}),date({1}))=0) ", parameter.MemberName, parameter2.MemberName); ; } + public virtual string Format(MethodCallExpressionModel model) + { + var str = "concat('" + model.Args[0].MemberValue.ObjToString() + "')"; + str = Regex.Replace(str, @"(\{\d+?\})", "',$1,'"); + var array = model.Args.Skip(1).Select(it => it.IsMember ? it.MemberName : it.MemberValue) + .Select(it => ToString(new MethodCallExpressionModel() + { + Args = new List() { + new MethodCallExpressionArgs(){ IsMember=true, MemberName=it } + } + })).ToArray(); + return string.Format("" + str + "", array); + } public override string DateIsSameByType(MethodCallExpressionModel model) { var parameter = model.Args[0];