0
我在應用程序的啓動時運行的所有遷移是這樣的:C#自動遷移從代碼自動遷移?
var configuration = new DbMigrationsConfiguration<MyContext>
{
TargetDatabase = new DbConnectionInfo("DataBase"),
AutomaticMigrationsEnabled = true,
AutomaticMigrationDataLossAllowed = true
};
_migrator = new DbMigrator(configuration);
_migrator.Update();
而且有一些代碼,第一方面:
public class MyContext : DbContext
{
public DbSet<MyObject> Objects { get; set; }
}
public class MyObject
{
public long Id {get;set;}
public byte[] Data {get;set;}
}
而且沒有使用任何預先生成(使用EF工具)遷移。起初它已經足夠了,但現在我需要運行一些自定義的SQL代碼來遷移數據庫到最新版本。例如,這一個:
public class MyCustomMigration : DbMigration
{
public override void Up()
{
Sql(@"
CREATE TABLE Files
(
Id BIGINT IDENTITY PRIMARY KEY,
Data VARBINARY(MAX) FILESTREAM
)
");
}
public override void Down()
{
DropTable("Files");
}
}
我該如何完成這項任務?我嘗試在配置中設置遷移目錄,但沒有成功(沒有任何反應,遷移未觸及)。