protected override SqlBuilder Where(BinaryExpression expression, SqlBuilder sqlBuilder) { bool hasHandle = false; if (CheckMemberIsNotColumn(expression, sqlBuilder)) { return(sqlBuilder); } //添加Where表达式左侧sql if (IsNeedsParentheses(expression, expression.Left)) { sqlBuilder.SqlWhereStr += "("; } if (expression.Left is MemberExpression && expression.Left.Type == typeof(bool) && expression.Left.NodeType == ExpressionType.MemberAccess && (expression.NodeType == ExpressionType.AndAlso || expression.Right is ConstantExpression)) { //解析(m=>m.IsAdmin) var memberExpression = expression.Left as MemberExpression; var tableName = memberExpression.Member.DeclaringType.GetTableName(sqlBuilder._dbSqlParser); sqlBuilder.SetTableAlias(tableName); string tableAlias = sqlBuilder.GetTableAlias(tableName); if (!string.IsNullOrWhiteSpace(tableAlias)) { tableAlias += "."; } //添加参数 var dbParamName = string.Empty; if (expression.Right is ConstantExpression) { hasHandle = true; var value = Convert.ToBoolean(((ConstantExpression)expression.Right).Value) ? 1 : 0; dbParamName = sqlBuilder.AddDbParameter(value); } else { dbParamName = sqlBuilder.AddDbParameter(1); } //添加关联条件 sqlBuilder.SqlWhereStr += " " + tableAlias + memberExpression.Member.Name; sqlBuilder.SqlWhereStr += " = "; sqlBuilder.SqlWhereStr += $"{dbParamName}"; } else { SqlProvider.Where(expression.Left, sqlBuilder); } if (IsNeedsParentheses(expression, expression.Left)) { sqlBuilder.SqlWhereStr += ")"; } if (!hasHandle) { //添加Where操作符 var whereOperator = " ="; if ((expression.Right is ConstantExpression) && ((ConstantExpression)expression.Right).Value == null) { whereOperator = OperatorParser(expression.NodeType, true); } else { whereOperator = OperatorParser(expression.NodeType); } sqlBuilder.SqlWhereStr += $"{whereOperator}"; //添加Where表达式右侧sql if (IsNeedsParentheses(expression, expression.Right)) { sqlBuilder.SqlWhereStr += "("; } if (expression.Right is MemberExpression && expression.Right.Type == typeof(bool) && expression.Right.NodeType == ExpressionType.MemberAccess && expression.NodeType == ExpressionType.AndAlso) { //解析(m=>m.IsAdmin) var memberExpression = expression.Right as MemberExpression; var tableName = memberExpression.Member.DeclaringType.GetTableName(sqlBuilder._dbSqlParser); sqlBuilder.SetTableAlias(tableName); string tableAlias = sqlBuilder.GetTableAlias(tableName); if (!string.IsNullOrWhiteSpace(tableAlias)) { tableAlias += "."; } //添加参数 var dbParamName = sqlBuilder.AddDbParameter(1); //添加关联条件 sqlBuilder.SqlWhereStr += " " + tableAlias + memberExpression.Member.Name; sqlBuilder.SqlWhereStr += " = "; sqlBuilder.SqlWhereStr += $"{dbParamName}"; } else { SqlProvider.Where(expression.Right, sqlBuilder); } if (IsNeedsParentheses(expression, expression.Right)) { sqlBuilder.SqlWhereStr += ")"; } } return(sqlBuilder); }