Script() public method

Translates this list of columns into SQL script.
public Script ( ) : string
return string
Ejemplo n.º 1
0
        /// <summary>
        /// Translates this table into a SQL script
        /// </summary>
        /// <returns></returns>
        public string Script()
        {
            var text = new StringBuilder();

            text.AppendFormat("CREATE TABLE [{0}](\r\n", Name);
            text.Append(Columns.Script());
            if (Constraints.Count > 0)
            {
                text.AppendLine();
            }
            //add primary keys
            foreach (var c in Constraints.Where(c => c.Type == ConstraintType.PrimaryKey))
            {
                text.AppendLine("   ," + c.Script());
            }
            text.AppendLine(");");
            text.AppendLine();

            //add indexes and constraints
            foreach (var c in Constraints.Where(c => c.Type != ConstraintType.PrimaryKey))
            {
                text.AppendLine(c.Script());
            }
            return(text.ToString());
        }
Ejemplo n.º 2
0
 public void Script()
 {
     var test = new Columns();
     test.Add(new Column("testing", ColumnTypes.Integer, true, null));
     Assert.Contains("testing", test.Script());
 }