protected virtual void WriteDropForeignKeys(Type daoType) { TableAttribute table = null; if (daoType.HasCustomAttributeOfType <TableAttribute>(out table)) { PropertyInfo[] properties = daoType.GetProperties(); foreach (PropertyInfo prop in properties) { ForeignKeyAttribute fk = null; if (prop.HasCustomAttributeOfType <ForeignKeyAttribute>(out fk)) { Builder.AppendFormat(@" IF EXISTS ( SELECT * FROM SYS.FOREIGN_KEYS WHERE object_id = OBJECT_ID(N'dbo.{0}') AND parent_object_id = OBJECT_ID(N'dbo.{1}') ) ALTER TABLE [{1}] DROP CONSTRAINT [{0}]", fk.ForeignKeyName, table.TableName); Go(); } } } }
protected override void WriteDropForeignKeys(Type daoType) { TableAttribute table = null; if (daoType.HasCustomAttributeOfType <TableAttribute>(out table)) { PropertyInfo[] properties = daoType.GetProperties(); foreach (PropertyInfo prop in properties) { ForeignKeyAttribute fk = null; if (prop.HasCustomAttributeOfType <ForeignKeyAttribute>(out fk)) { Builder.AppendFormat("ALTER TABLE `{0}` DROP FOREIGN KEY {1}", table.TableName, fk.ForeignKeyName); Go(); } } } }
protected override void WriteDropForeignKeys(Type daoType) { TableAttribute table = null; if (daoType.HasCustomAttributeOfType <TableAttribute>(out table)) { PropertyInfo[] properties = daoType.GetProperties(); foreach (PropertyInfo prop in properties) { ForeignKeyAttribute fk = null; if (prop.HasCustomAttributeOfType <ForeignKeyAttribute>(out fk)) { Builder.AppendFormat("ALTER TABLE {0} DROP CONSTRAINT {1}", GetFormattedTableName(table.TableName), GetFirstThirtyCharacters(fk.ForeignKeyName)); Go(); } } } }