diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs b/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs index 256ad7ecb..e53847c1c 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs @@ -400,9 +400,9 @@ namespace OrmTest.UnitTest expContext.Resolve(exp, ResolveExpressType.WhereSingle); var value = expContext.Result.GetString(); var pars = expContext.Parameters; - base.Check(value, pars, "( CAST( DateName(Year,[Datetime1]) +'-'+ DateName(Month,[Datetime1]) +'-'+ DateName(Day,[Datetime1]) AS DATETIME) > @Date0 )", new List() + base.Check(value, pars, "( ( [Bool1]=1 ) AND ( [Bool1]=1 ) )", new List() { - new SugarParameter("@Date0",DateTime.Now.Date), + }, "whereSingle26"); } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs index b39da6e2a..fae3ce837 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs @@ -58,7 +58,7 @@ namespace SqlSugar public static bool IsLogicOperator(string operatorValue) { - return operatorValue == "&&" || operatorValue == "||"; + return operatorValue == "&&" || operatorValue == "||"||operatorValue == "AND" || operatorValue == "OR"; } public static bool IsLogicOperator(Expression expression) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs index d3bb16e88..3f7ad4fd7 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs @@ -21,13 +21,14 @@ namespace SqlSugar var isBool = expression.Type == UtilConstants.BoolType; var isValueBool = isValue && isBool && parameter.BaseExpression == null; var isLength = memberName == "Length" && childIsMember && childExpression.Type == UtilConstants.StringType; - var isDateValue = memberName.IsIn(Enum.GetNames(typeof(DateType))) &&(childIsMember&&childExpression.Type == UtilConstants.DateType); + var isDateValue = memberName.IsIn(Enum.GetNames(typeof(DateType))) && (childIsMember && childExpression.Type == UtilConstants.DateType); var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty(); var isHasValue = isLogicOperator && memberName == "HasValue" && expression.Expression != null && expression.NodeType == ExpressionType.MemberAccess; var isDateDate = memberName == "Date" && expression.Expression.Type == UtilConstants.DateType; var isMemberValue = expression.Expression != null && expression.Expression.NodeType != ExpressionType.Parameter && !isValueBool; var isSingle = parameter.Context.ResolveType == ResolveExpressType.WhereSingle; - + var fieldIsBool = isBool && isLogicOperator; + baseParameter.ChildExpression = expression; if (isLength) { ResolveLength(parameter, isLeft, expression); @@ -56,9 +57,12 @@ namespace SqlSugar { ResolveMemberValue(parameter, baseParameter, isLeft, isSetTempData, expression); } + else if (fieldIsBool) + { + ResolvefieldIsBool(parameter, baseParameter, isLeft, isSetTempData, expression, isSingle); + } else { - baseParameter.ChildExpression = expression; string fieldName = string.Empty; switch (parameter.Context.ResolveType) { @@ -165,6 +169,19 @@ namespace SqlSugar AppendValue(parameter, isLeft, value); } } + private void ResolvefieldIsBool(ExpressionParameter parameter, ExpressionParameter baseParameter, bool? isLeft, bool isSetTempData, MemberExpression expression, bool isSingle) + { + var fieldName = GetName(parameter, expression, isLeft, isSingle); + if (isSetTempData) + { + baseParameter.CommonTempData = fieldName; + } + else + { + fieldName = this.Context.DbMehtods.EqualTrue(fieldName.ObjToString()); + AppendMember(parameter, isLeft, fieldName); + } + } private void ResolveDateDate(ExpressionParameter parameter, bool? isLeft, MemberExpression expression) { @@ -295,7 +312,7 @@ namespace SqlSugar string shortName = expression.Expression.ToString(); string fieldName = expression.Member.Name; fieldName = this.Context.GetDbColumnName(expression.Expression.Type.Name, fieldName); - fieldName = Context.GetTranslationColumnName(shortName +UtilConstants.Dot+ fieldName); + fieldName = Context.GetTranslationColumnName(shortName + UtilConstants.Dot + fieldName); return fieldName; }