From 2ec64ec04e8cf06e55b41f80388144332b852670 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 26 Nov 2022 22:01:57 +0800 Subject: [PATCH] Update exp to sql --- .../ExpressionsToSql/Common/ExpressionTool.cs | 16 ++++++++++++++++ .../MethodCallExpressionResolve_Helper.cs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs index 6c96ad604..7035b5396 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs @@ -559,5 +559,21 @@ namespace SqlSugar } return false; } + + internal static bool IsIsNullSubQuery(Expression it) + { + if (it is MethodCallExpression) + { + var method = (MethodCallExpression)it; + if (method.Method.Name == "IsNull") + { + if (method.Arguments.Count==2&&IsSubQuery(method.Arguments[0])) + { + return true; + } + } + } + return false; + } } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs index 419c987c1..14fa0832b 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs @@ -116,6 +116,22 @@ namespace SqlSugar } } } + else if (this.Context.IsSingle && args.Any(it => ExpressionTool.IsIsNullSubQuery(it)) ) + { + var exp = base.BaseParameter?.BaseParameter?.BaseParameter?.CurrentExpression; + if (exp is LambdaExpression) + { + SetShortName(exp); + } + else if (exp is UnaryExpression) + { + exp = base.BaseParameter?.BaseParameter?.BaseParameter?.BaseParameter?.CurrentExpression; + if (exp is LambdaExpression) + { + SetShortName(exp); + } + } + } var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression; var isConst = item is ConstantExpression; var isIIF = name == "IIF";