diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs index c66479057..f027eca57 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs @@ -51,7 +51,7 @@ namespace SqlSugar { JoinString(parameter, expression); } - else if (IsUpdateJson(parameter,expression, operatorValue)) + else if (IsUpdateJson(parameter, expression, operatorValue)) { parameter.CommonTempData = "IsJson=true"; DefaultBinary(parameter, expression, operatorValue); @@ -63,11 +63,39 @@ namespace SqlSugar DefaultBinary(parameter, expression, operatorValue); parameter.CommonTempData = null; } + else if (IsBinaryGroup(operatorValue,expression)) + { + var isComparisonOperator = ExpressionTool.IsComparisonOperator(expression); + var getLeft=GetNewExpressionValue(expression.Left); + var getRight = GetNewExpressionValue(expression.Right); + base.Context.Result.Append($"( {getLeft} {operatorValue} {getRight} )"); + } else { DefaultBinary(parameter, expression, operatorValue); } } + + private bool IsBinaryGroup(string operatorValue, BinaryExpression expression) + { + var left = ExpressionTool.RemoveConvert(expression.Left); + var right = ExpressionTool.RemoveConvert(expression.Right); + if (operatorValue?.IsIn("AND","OR")==true&&left is BinaryExpression&& right is BinaryExpression) + { + + var leftChild = ExpressionTool.RemoveConvert((left as BinaryExpression).Right); + var rightChild = ExpressionTool.RemoveConvert((right as BinaryExpression).Right); + if (ExpressionTool.GetMethodName(leftChild)=="Select" + && ExpressionTool.GetMethodName(rightChild) == "Select" + && ExpressionTool.ContainsMethodName(left as BinaryExpression, "Group") + &&ExpressionTool.ContainsMethodName(right as BinaryExpression, "Group")) + { + return true; + } + } + return false; + } + private bool IsUpdateArray(ExpressionParameter parameter, BinaryExpression expression, string operatorValue) { var isOk = parameter.Context.ResolveType == ResolveExpressType.WhereSingle && operatorValue == "=" && (expression.Left is MemberExpression) && expression.Left.Type.IsClass();