private void VisitBinary(DbBinaryExpression expression, string separator)
		{
			commandText.Append("(");
			expression.Left.Accept(this);
			commandText.Append(separator);
			expression.Right.Accept(this);
			commandText.Append(")");
		}
 private void VisitBinary(DbBinaryExpression expr)
 {
     VisitExprKind(expr.ExpressionKind);
     _key.Append('(');
     expr.Left.Accept(this);
     _key.Append(',');
     expr.Right.Accept(this);
     _key.Append(')');
 }
 protected virtual void VisitBinary(DbBinaryExpression expression)
 {
   if (expression == null) throw new ArgumentException("expression");
   this.VisitExpression(expression.Left);
   this.VisitExpression(expression.Right);
 }
 private void ValidateBinaryExpression(DbBinaryExpression binaryExpression, DbBinaryExpressionType binaryExpressionType)
 {
     Assert.IsNotNull(binaryExpression);
     Assert.IsNotNull(binaryExpression.LeftExpression);
     Assert.IsNotNull(binaryExpression.RightExpression);
     Assert.IsTrue(binaryExpression.ExpressionType == DbExpressionType.Binary);
     Assert.IsTrue(binaryExpression.BinaryExpressionType == binaryExpressionType);
 }
 private void BeginBinary(DbBinaryExpression e)
 {
     Begin(e);
     Begin("Left");
     Dump(e.Left);
     End("Left");
     Begin("Right");
     Dump(e.Right);
     End("Right");
 }
        public static bool ExpressionEquals(DbBinaryExpression exp1, DbBinaryExpression exp2)
        {
            if (exp1.Method != exp2.Method)
                return false;
            if (!EqualsCompare(exp1.Left, exp2.Left))
                return false;
            if (!EqualsCompare(exp1.Right, exp2.Right))
                return false;

            return true;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Visits the <see cref="DbBinaryExpression"/>.
 /// </summary>
 /// <param name="expression">The expression.</param>
 public abstract void Visit(DbBinaryExpression expression);
        static void StringConcat(DbBinaryExpression exp, SqlGenerator generator)
        {
            List <DbExpression> operands = new List <DbExpression>();

            operands.Add(exp.Right);

            DbExpression    left = exp.Left;
            DbAddExpression e    = null;

            while ((e = (left as DbAddExpression)) != null && (e.Method == UtilConstants.MethodInfo_String_Concat_String_String || e.Method == UtilConstants.MethodInfo_String_Concat_Object_Object))
            {
                operands.Add(e.Right);
                left = e.Left;
            }

            operands.Add(left);

            DbExpression        whenExp     = null;
            List <DbExpression> operandExps = new List <DbExpression>(operands.Count);

            for (int i = operands.Count - 1; i >= 0; i--)
            {
                DbExpression operand = operands[i];
                DbExpression opBody  = operand;
                if (opBody.Type != UtilConstants.TypeOfString)
                {
                    // 需要 cast type
                    opBody = DbExpression.Convert(opBody, UtilConstants.TypeOfString);
                }

                DbExpression equalNullExp = DbExpression.Equal(opBody, UtilConstants.DbConstant_Null_String);

                if (whenExp == null)
                {
                    whenExp = equalNullExp;
                }
                else
                {
                    whenExp = DbExpression.And(whenExp, equalNullExp);
                }

                operandExps.Add(opBody);
            }

            generator._sqlBuilder.Append("CASE", " WHEN ");
            whenExp.Accept(generator);
            generator._sqlBuilder.Append(" THEN ");
            DbConstantExpression.Null.Accept(generator);
            generator._sqlBuilder.Append(" ELSE ");

            generator._sqlBuilder.Append("(");

            for (int i = 0; i < operandExps.Count; i++)
            {
                if (i > 0)
                {
                    generator._sqlBuilder.Append(" || ");
                }

                generator._sqlBuilder.Append("IFNULL(");
                operandExps[i].Accept(generator);
                generator._sqlBuilder.Append(",");
                DbConstantExpression.StringEmpty.Accept(generator);
                generator._sqlBuilder.Append(")");
            }

            generator._sqlBuilder.Append(")");

            generator._sqlBuilder.Append(" END");
        }
Exemplo n.º 9
0
 /// <summary>
 /// Constructs a new pattern that is matched iff the argument expression is a <see cref="DbBinaryExpression"/> with left and right subexpressions that match the corresponding <paramref name="leftPattern"/> and <paramref name="rightPattern"/> patterns
 /// </summary>
 internal static Func <DbExpression, bool> MatchBinary(Func <DbExpression, bool> leftPattern, Func <DbExpression, bool> rightPattern)
 {
     return(e => { DbBinaryExpression binEx = (e as DbBinaryExpression); return (binEx != null && leftPattern(binEx.Left) && rightPattern(binEx.Right)); });
 }