public IEnumerable <string> GetScriptCommands(SqlSyntax syntax) { return(GetScriptBlocks(syntax).SelectMany(block => block.GetCommands(syntax))); }
public IEnumerable <ScriptBlock> GetScriptBlocks(SqlSyntax syntax) { var createColumns = Create.OfType <Column>(); var createOther = Create.Where(obj => !obj.GetType().Equals(typeof(Column))); List <ScriptBlock> fkScript = new List <ScriptBlock>(); foreach (var columnGrp in createColumns.GroupBy(item => item.Table)) { string columnList = string.Join(", ", columnGrp.Select(col => col.Name)); if (columnGrp.Key.IsEmpty) { yield return(new ScriptBlock() { ActionType = ActionType.Create, Objects = columnGrp, Commands = RebuildCommands(syntax, columnGrp, columnList) }); foreach (var fk in columnGrp.Key.GetForeignKeys(Source)) { fkScript.Add(new ScriptBlock() { ActionType = ActionType.Create, Objects = columnGrp, Commands = CreateCommands(syntax, fk) }); } } else { foreach (var col in columnGrp) { yield return(new ScriptBlock() { ActionType = ActionType.Create, Objects = new DbObject[] { col }, Commands = CreateCommands(syntax, col) }); if (col.IsForeignKey(Source, out ForeignKey fk)) { fkScript.Add(new ScriptBlock() { ActionType = ActionType.Create, Objects = new DbObject[] { col }, Commands = CreateCommands(syntax, fk) }); } } } } foreach (var create in createOther) { yield return(new ScriptBlock() { ActionType = ActionType.Create, Objects = new DbObject[] { create }, Commands = CreateCommands(syntax, create) }); } foreach (var alter in Alter) { yield return(new ScriptBlock() { ActionType = ActionType.Alter, Objects = new DbObject[] { alter }, Commands = AlterCommands(syntax, alter) }); } foreach (var drop in Drop) { yield return(new ScriptBlock() { ActionType = ActionType.Drop, Objects = new DbObject[] { drop }, Commands = DropCommands(syntax, drop) }); } foreach (var fk in fkScript) { yield return(fk); } }