From a72f86f0d9a39ae30b4aebedaeef67a55a84a1ed Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 22 Feb 2024 21:53:52 +0800 Subject: [PATCH] Synchronization code --- .../ExpressionsToSql/ResolveItems/BaseResolve_Item.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve_Item.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve_Item.cs index 6f87dc6f7..08878307f 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve_Item.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve_Item.cs @@ -328,6 +328,11 @@ namespace SqlSugar if (this.Context.Result.IsLockCurrentParameter == false) { var expression = ((UnaryExpression)item).Operand as MemberExpression; + var negateString = string.Empty; + if (item.NodeType == ExpressionType.Negate) + { + negateString = " -1*"; + } var isDateTimeNow = ((UnaryExpression)item).Operand.ToString() == "DateTime.Now"; if (expression.Expression == null && !isDateTimeNow) { @@ -337,14 +342,14 @@ namespace SqlSugar this.Expression = item; this.Start(); parameter.IsAppendResult(); - this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString())); + this.Context.Result.Append(negateString + this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString())); this.Context.Result.CurrentParameter = null; } else if (expression.Expression is ConstantExpression || isDateTimeNow) { string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex; this.Context.ParameterIndex++; - parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName)); + parameter.Context.Result.Append(negateString + this.Context.GetAsString(asName, parameterName)); this.Context.Parameters.Add(new SugarParameter(parameterName, ExpressionTool.GetMemberValue(expression.Member, expression))); } else @@ -355,7 +360,7 @@ namespace SqlSugar this.Expression = expression; this.Start(); parameter.IsAppendResult(); - this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString())); + this.Context.Result.Append(negateString + this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString())); this.Context.Result.CurrentParameter = null; } }