//public static void RecreateName(this IConstraint cnt) //{ // if (cnt is IPrimaryKey) cnt.Name = PkName(cnt.Table); // else if (cnt is ForeignKey) cnt.Name = FkName(cnt.Table, ((ForeignKey)cnt).Columns); // else if (cnt is CheckConstraint) cnt.Name = CheckName(cnt.Table); // else if (cnt is UniqueConstraint) cnt.Name = UniqueName(cnt.Table, ((UniqueConstraint)cnt).Columns); //} public static void RenameTable(TableStructure tbl, IEnumerable tables, NameWithSchema newname) { var oldname = tbl.FullName; tbl.FullName = newname; foreach (TableStructure t in tables) { foreach (Constraint cnt in t.Constraints) { var fk = cnt as ForeignKey; if (fk != null) { if (fk.PrimaryKeyTable == oldname) { fk.PrimaryKeyTable = newname; if (fk.Columns.Count == 1 && fk.Columns[0].ColumnName.StartsWith(oldname.Name)) { string postfix = fk.Columns[0].ColumnName.Substring(oldname.Name.Length); fk.Columns[0] = new ColumnReference(newname.Name + postfix); ((ColumnStructure)t.Columns[oldname.Name + postfix]).ColumnName = newname.Name + postfix; } fk.Name = DbObjectNameTool.ConstraintName(fk); } } } } foreach (Constraint cnt in tbl.Constraints) { //cnt.Table = newname; cnt.Name = DbObjectNameTool.ConstraintName(cnt); } }
public override string RenameConstraint(IConstraint constraint) { return(DbObjectNameTool.ConstraintName(constraint)); }