From 92f6a6feff6aa6076e2fe498b9181e98ea885786 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 28 Apr 2025 22:33:03 +0800 Subject: [PATCH] Exp to sql --- .../SqlSugar/ExpressionsToSql/Common/ExpressionResult.cs | 7 +++++++ .../ResolveItems/ConditionalExpressionResolve.cs | 1 + Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/ExpressionResult.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/ExpressionResult.cs index cb34b873f..57fcb4d4b 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/ExpressionResult.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/ExpressionResult.cs @@ -147,6 +147,13 @@ namespace SqlSugar default: break; } + if (this.Result.Length > 0 && this.Result[this.Result.Length - 1] == ',') + { + if (parameter?.ToString()?.StartsWith(" AS ") ==true && parameter?.ToString()?.EndsWith(" ,")==true) + { + this.Result.Length--; // 直接删掉最后一个字符 + } + } this.Result.Append(parameter); } diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/ConditionalExpressionResolve.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/ConditionalExpressionResolve.cs index 0c950384d..cb0670a57 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/ConditionalExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/ConditionalExpressionResolve.cs @@ -27,6 +27,7 @@ namespace SqlSugar var value = ExpressionTool.DynamicInvoke(express.Test); if (value is bool boolValue) { + args[0] = boolValue ? UtilConstants.ExpTrue :UtilConstants.ExpFalse; // 根据结果选择分支 var next = boolValue ? express.IfTrue : express.IfFalse; args[1] = next; diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs index 421a8000d..86a316366 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Dynamic; using System.Globalization; using System.Linq; +using System.Linq.Expressions; using System.Text; namespace SqlSugar { @@ -77,5 +78,8 @@ namespace SqlSugar "Millisecond", "Date" }; + + public static ConstantExpression ExpTrue = Expression.Constant(true); + public static ConstantExpression ExpFalse = Expression.Constant(false); } }