protected virtual Expression VisitConstraint(ConstraintExpression node)
        {
            switch (node.NodeType)
            {
            case ExpressionType.Default:
            case ExpressionType.Add:
                if (node.NodeType == ExpressionType.Add)
                {
                    Append("ADD");
                }
                Append("CONSTRAINT");
                Visit(node.Name);
                switch (node.ConstraintType)
                {
                case ConstraintType.PrimaryKey:
                    Append("PRIMARY KEY");
                    if (node.IndexType.HasFlag(IndexType.Unique))
                    {
                        Append("UNIQUE");
                    }
                    Append(node.IndexType.HasFlag(IndexType.Clustered) ? "CLUSTERED" : "NONCLUSTERED");
                    break;

                case ConstraintType.ForeignKey:
                    Append("FOREIGN KEY");
                    break;

                default:
                    throw new NotSupportedException(node.ConstraintType.ToString());
                }
                Append("(");
                Visit(node.Columns);
                Append(")", false);
                if (node.ReferenceTable != null)
                {
                    Append("REFERENCES");
                    Visit(node.ReferenceTable);
                    Append("(", false);
                    Visit(node.ReferenceColumn);
                    Append(")", false);
                }
                break;

            case ExpressionType.Subtract:
                Append("DROP CONSTRAINT");
                Visit(node.Name);
                break;

            default:
                throw new NotSupportedException("Invalid node type: " + node.NodeType);
            }
            return(node);
        }
 public void DropConstraint(string name)
 {
     ConstraintExpression constraint;
     if (Constraints == null)
     {
         constraint = new ConstraintExpression(name, ExpressionType.Subtract);
         Constraints = constraint;
     }
     else
     {
         constraint = Constraints as ConstraintExpression;
         if (constraint == null) throw new NotSupportedException();
         if (constraint.NodeType != ExpressionType.Subtract) throw new NotSupportedException();
         constraint.AddName(new ObjectNameExpression(name));
     }
 }
        public void DropConstraint(string name)
        {
            ConstraintExpression constraint;

            if (Constraints == null)
            {
                constraint  = new ConstraintExpression(name, ExpressionType.Subtract);
                Constraints = constraint;
            }
            else
            {
                constraint = Constraints as ConstraintExpression;
                if (constraint == null)
                {
                    throw new NotSupportedException();
                }
                if (constraint.NodeType != ExpressionType.Subtract)
                {
                    throw new NotSupportedException();
                }
                constraint.AddName(new ObjectNameExpression(name));
            }
        }
 protected virtual Expression VisitConstraint(ConstraintExpression node)
 {
     switch (node.NodeType)
     {
         case ExpressionType.Default:
         case ExpressionType.Add:
             if (node.NodeType == ExpressionType.Add) Append("ADD");
             Append("CONSTRAINT");
             Visit(node.Name);
             switch (node.ConstraintType)
             {
                 case ConstraintType.PrimaryKey:
                     Append("PRIMARY KEY");
                     if (node.IndexType.HasFlag(IndexType.Unique)) Append("UNIQUE");
                     Append(node.IndexType.HasFlag(IndexType.Clustered) ? "CLUSTERED" : "NONCLUSTERED");
                     break;
                 case ConstraintType.ForeignKey:
                     Append("FOREIGN KEY");
                     break;
                 default:
                     throw new NotSupportedException(node.ConstraintType.ToString());
             }
             Append("(");
             Visit(node.Columns);
             Append(")", false);
             if (node.ReferenceTable != null)
             {
                 Append("REFERENCES");
                 Visit(node.ReferenceTable);
                 Append("(", false);
                 Visit(node.ReferenceColumn);
                 Append(")", false);
             }
             break;
         case ExpressionType.Subtract:
             Append("DROP CONSTRAINT");
             Visit(node.Name);
             break;
         default:
             throw new NotSupportedException("Invalid node type: " + node.NodeType);
     }
     return node;
 }