我正在使用Fluent Migrator来更新数据库。 Up和Down功能完美运行。下一步是我想要创建视图。这些我想从我拥有的.SQL文件运行。我想在每次运行所有迁移之后运行它。
目前我所拥有的是:
var blah = new MigrationConventions();
var maintenanceLoader = new MaintenanceLoader(_migrate, blah);
maintenanceLoader.ApplyMaintenance(MigrationStage.AfterAll);
和一个班级
[Maintenance(MigrationStage.AfterAll)]
public class ViewMaintenance
{
public ViewMaintenance() {
var blah = 123;
}
}
这不会被触发,因为在maintenanceLoader中可以找到0个元素。我正在插入_migrate,其定义如下:
var runnerContext = new RunnerContext(new TextWriterAnnouncer(UpdateText));
_migrate = new MigrationRunner(
Assembly.GetExecutingAssembly(),
runnerContext,
new SqlServerProcessor(
new SqlConnection(connectionString),
new SqlServer2012Generator(),
new TextWriterAnnouncer(UpdateText),
new ProcessorOptions(),
new SqlServerDbFactory()));
为什么无法扫描Assembly.GetExecutingAssembly()
,并找到[Maintenance(MigrationStage.AfterAll)]
?
我还希望ViewMaintenance类能够运行Migration类所具有的Execute.Sql(
。
答案 0 :(得分:0)
我下载了源代码并想出来了。
在类中我希望运行维护,我需要从: Migration
类继承,就像迁移(duh ..)一样。然后,它将可以访问迁移中可访问的所有内容,包括Execute.Sql(
。
当继承它时,Fluent Migrator中的Reflection将搜索它,找到它,并使用设置的属性在运行所有迁移后运行它。
不需要此部分:
var blah = new MigrationConventions();
var maintenanceLoader = new MaintenanceLoader(_migrate, blah);
maintenanceLoader.ApplyMaintenance(MigrationStage.AfterAll);
整洁:)