private TextFragments FormatIndex(string lineBreak) { var frags = new TextFragments(); if (DbIndex.IsUnique) { frags.AddPrimary("UNIQUE "); } frags.AddPrimary(DbIndex.Type + " INDEX "); frags.AddPrimary("[" + DbIndex.Name + "]"); frags.AddSecondary(" ON "); frags.AddPrimary("[" + DbIndex.Parent.SchemaName + "].[" + DbIndex.Parent.Name + "]"); frags.Add(FormatColumns(lineBreak)); return(frags); }
private TextFragments FormatColumns(string lb) { var frags = new TextFragments(); frags.AddSecondary("(" + lb); var isFirst = true; var mainCols = DbIndex.Columns.Where(p => !p.Included).OrderBy(p => p.IndexColumnId); foreach (var column in mainCols) { if (!isFirst) { frags.AddSecondary("," + lb); } isFirst = false; frags.AddSecondary("\t"); frags.AddPrimary("[" + column.ColumnName + "]"); frags.AddSecondary(column.IsDesc ? " DESC" : " ASC"); } frags.AddSecondary(lb + ")" + lb); var includedCols = DbIndex.Columns.Where(p => p.Included).OrderBy(p => p.IndexColumnId); if (includedCols.Count() > 0) { frags.AddSecondary("INCLUDE (" + lb); isFirst = true; foreach (var column in includedCols) { if (!isFirst) { frags.AddSecondary("," + lb); } isFirst = false; frags.AddSecondary("\t"); frags.AddPrimary("[" + column.ColumnName + "]"); } frags.AddSecondary(lb + ")" + lb); } return(frags); }