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");
}
}
我该如何完成这项任务?我尝试在配置中设置迁移目录,但没有成功(没有任何反应,迁移未触及)。