Esempio n. 1
0
        //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);
            }
        }
Esempio n. 2
0
 protected virtual Constraint MigrateConstraintOrIndex(Constraint cnt, IMigrationProfile profile, IProgressInfo progress)
 {
     if (cnt is IPrimaryKey)
     {
         if (DialectCaps.AnonymousPrimaryKey)
         {
             PrimaryKey pk = (PrimaryKey)cnt;
             pk.Name = DbObjectNameTool.PkName(pk.Table.FullName);
         }
     }
     return(cnt);
 }
Esempio n. 3
0
        internal override string DoCreateName(ISqlDialect dialect)
        {
            if (dialect != null && dialect.DialectCaps.AnonymousPrimaryKey && Type == EditorIndexOrKeyType.PrimaryKey)
            {
                return(null);
            }
            switch (Type)
            {
            case EditorIndexOrKeyType.PrimaryKey:
                return(DbObjectNameTool.PkName(m_table));

            case EditorIndexOrKeyType.Index:
                return(DbObjectNameTool.IndexName(m_table, m_columns));

            case EditorIndexOrKeyType.UniqueConstraint:
                return(DbObjectNameTool.UniqueName(m_table, m_columns));
            }
            throw new InternalError("DAE-00176 internal error");
        }
Esempio n. 4
0
 internal override string DoCreateName(ISqlDialect dialect)
 {
     return(m_frame.GetUniqueName(DbObjectNameTool.CheckName(m_table)));
 }
Esempio n. 5
0
 internal override string DoCreateName(ISqlDialect dialect)
 {
     return(DbObjectNameTool.FkName(m_table, from col in m_columns select(IColumnReference) col.SrcName));
 }
Esempio n. 6
0
 public override string RenameConstraint(IConstraint constraint)
 {
     return(DbObjectNameTool.ConstraintName(constraint));
 }