Ejemplo n.º 1
0
 public SqlConditionItem AddCondition(SqlConditionItem condition)
 {
     if (Conditions == null)
     {
         Conditions = new List <SqlConditionItem>();
     }
     Conditions.Add(condition);
     return(condition);
 }
Ejemplo n.º 2
0
        private static void AppendCondition(ScriptStringBuilder sql, SqlConditionItem condition)
        {
            var first = true;

            var expression = condition as SqlExpression;

            if (expression != null)
            {
                if (expression.Conditions != null && expression.Conditions.Count > 0)
                {
                    sql.AppendLine("(");
                    sql.BeginBlock();
                    foreach (var sub in expression.Conditions)
                    {
                        if (!first)
                        {
                            switch (sub.Operation)
                            {
                            case ExpressionOperation.And:
                                sql.AppendLine(" AND");
                                break;

                            case ExpressionOperation.Or:
                                sql.AppendLine(" OR");
                                break;

                            case ExpressionOperation.AndNot:
                                sql.AppendLine(" AND NOT");
                                break;

                            case ExpressionOperation.OrNot:
                                sql.AppendLine(" OR NOT");
                                break;
                            }
                        }
                        else
                        {
                            first = false;
                        }

                        AppendCondition(sql, sub);
                    }
                    sql.EndBlock();
                    sql.Append(")");
                }
            }
            else
            {
                sql.Append(((SqlCondition)condition).Expression);
            }
        }