本文整理汇总了C#中IMigrationGenerator.DropConstraint方法的典型用法代码示例。如果您正苦于以下问题:C# IMigrationGenerator.DropConstraint方法的具体用法?C# IMigrationGenerator.DropConstraint怎么用?C# IMigrationGenerator.DropConstraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMigrationGenerator
的用法示例。
在下文中一共展示了IMigrationGenerator.DropConstraint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteScripts
public static void ExecuteScripts(string providerName, string connectionString, string tableName, IMigrationGenerator migrationGenerator)
{
var table = CreateTestTable(tableName);
var newColumn = CreateNewColumn();
var uniqueConstraint = CreateUniqueConstraint(newColumn);
var fk = CreateForeignKey(table);
var index = CreateUniqueIndex(newColumn, tableName);
var createTable = migrationGenerator.AddTable(table);
var addColumn = migrationGenerator.AddColumn(table, newColumn);
var addUniqueConstraint = migrationGenerator.AddConstraint(table, uniqueConstraint);
var addForeignKey = migrationGenerator.AddConstraint(table, fk);
var addUniqueIndex = migrationGenerator.AddIndex(table, index);
var dropUniqueIndex = migrationGenerator.DropIndex(table, index);
var dropForeignKey = migrationGenerator.DropConstraint(table, fk);
var dropUniqueConstraint = migrationGenerator.DropConstraint(table, uniqueConstraint);
var dropColumn = migrationGenerator.DropColumn(table, newColumn);
var dropTable = migrationGenerator.DropTable(table);
var factory = DbProviderFactories.GetFactory(providerName);
using (var con = factory.CreateConnection())
{
con.ConnectionString = connectionString;
using (var cmd = con.CreateCommand())
{
con.Open();
using (var tx = con.BeginTransaction())
{
cmd.Transaction = tx;
Execute(cmd, createTable);
Execute(cmd, addColumn);
Execute(cmd, addUniqueConstraint);
Execute(cmd, addForeignKey);
Execute(cmd, dropForeignKey);
Execute(cmd, dropUniqueConstraint);
//now we've dropped the unique constraint, add a unique index
Execute(cmd, addUniqueIndex);
Execute(cmd, dropUniqueIndex);
Execute(cmd, dropColumn);
Execute(cmd, dropTable);
}
}
}
}