From 00fa46087d268c08380afc34202aa911a68adf4d Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 1 Apr 2023 18:39:24 +0800 Subject: [PATCH] Synchronization code --- .../ExpressionsToSql/DbMethods/DefaultDbMethod.cs | 13 ++++++++++--- .../SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs | 1 + .../MethodCallExpressionResolve_Helper.cs | 9 ++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs index 6a1a902df..f164bad08 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs @@ -370,9 +370,16 @@ namespace SqlSugar public virtual string MappingColumn(MethodCallExpressionModel model) { - var parameter = model.Args[0]; - var parameter1 = model.Args[1]; - return string.Format("{0}", parameter1.MemberValue); + if (model.Args.Count == 1) + { + return string.Format("{0}", model.Args[0].MemberValue); + } + else + { + var parameter = model.Args[0]; + var parameter1 = model.Args[1]; + return string.Format("{0}", parameter1.MemberValue); + } } public virtual string IsNull(MethodCallExpressionModel model) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs index 299e14647..e7f289f0a 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs @@ -241,6 +241,7 @@ namespace SqlSugar public static int AggregateCount(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); } public static int AggregateDistinctCount(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); } public static TResult MappingColumn(TResult type,string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); } + public static TResult MappingColumn(string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); } /// ///Example: new NewT(){name=SqlFunc.GetSelfAndAutoFill(it)} Generated SQL it.* /// diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs index ae8b1817f..1c2c80846 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs @@ -675,7 +675,14 @@ namespace SqlSugar var mappingColumnResult = this.Context.DbMehtods.MappingColumn(model); var isValid = model.Args[0].IsMember && model.Args[1].IsMember == false; //Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right"); - this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString()); + if (model.Args.Count > 1) + { + this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString()); + } + else + { + this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString()); + } if (mappingColumnResult == "") { return model.Args[1].MemberName.ObjToString().TrimStart('\'').TrimEnd('\'');