C# 使用FluentMigrator更改约定

C# 使用FluentMigrator更改约定,c#,fluent-migrator,C#,Fluent Migrator,在FluentMigrator中,哪里是覆盖默认迁移约定的适当位置?这应该在运行程序中完成,还是在迁移过程中完成?还是其他地方 具体来说,我想更改索引命名约定,以匹配ServiceStack使用的命名约定(例如,IX_Foo\u Bar=>uidx_Foo\u Bar) 我看到方法MigrationBase.ApplyConventions(imiglationcontext)其中imiglationcontext有一个imiglationconventions属性。。。我是否应该在迁移中创建自

在FluentMigrator中,哪里是覆盖默认迁移约定的适当位置?这应该在运行程序中完成,还是在迁移过程中完成?还是其他地方

具体来说,我想更改索引命名约定,以匹配ServiceStack使用的命名约定(例如,
IX_Foo\u Bar
=>
uidx_Foo\u Bar


我看到方法
MigrationBase.ApplyConventions(imiglationcontext)
其中
imiglationcontext
有一个
imiglationconventions
属性。。。我是否应该在迁移中创建自己的
MigrationContext
?如果我希望所有迁移都使用相同的约定,该怎么办?

这是我发现的更改约定的唯一方法。您需要创建一个扩展“FluentMigrator.Migration”的抽象类,以更改其约定。然后,所有迁移类都应该扩展该类,而不是FluentMigrator.migration

公共抽象类基类迁移:迁移
{
//更新向上迁移的约定
公共覆盖无效GetUpExpressions(IMiglationContext上下文)
{
此.UpdateConventions(上下文);
base.GetUpExpressions(上下文);
}
//更新向下迁移的约定
公共覆盖无效GetDownExpressions(IMiglationContext上下文)
{
此.UpdateConventions(上下文);
base.GetDownExpressions(上下文);
}
//改变惯例
public void UpdateConventions(IMiglationContext上下文)
{
var约定=((MigrationConventions)context.conventions);
conventions.GetIndexName=index=>DefaultMigrationConventions.GetIndexName(index).Replace(“IX_”,“uidx_”);
}
}

不错。我们已经有了一个用于版本控制方案的自定义基类,所以这还不错。