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 anything that is not an index
foreach (var c in Constraints.Where(c => c.Type != ContraintType.Index))
{
text.AppendLine(" ," + c.Script());
}
text.AppendLine();
text.AppendLine(");");
//add indexes
foreach (var c in Constraints.Where(c => c.Type == ContraintType.Index))
{
text.AppendLine(c.Script());
text.AppendLine(";");
}
return text.ToString();
}
#endregion
public void Create_Script() { var c = new Column("testing", ColumnTypes.Bigint, true); var cc = new Constraint("ix_testing", ContraintType.Index, "testing"); var test = new Table("test"); test.Constraints.Add(cc); test.Columns.Add(c); //set the table reference foreach (var ccc in test.Constraints) { ccc.Table = test.Info; } Assert.Contains("test", test.Script()); }