自定义 Entity Framework 核心迁移脚本?

Custom Entity Framework Core Migration Script?

我需要做一个 "full-text indexed" 但我正在使用 ef core 2.1 代码优先迁移,但是完整索引在核心中没有优先 class 支持。

如何编写自己的迁移,以便在应用其他生成的迁移时应用?

您必须创建空迁移,然后在 Up 方法中您可以编写 SQL 查询。

  1. 通过 运行 在包中添加迁移命令创建空迁移 管理员控制台。
  2. 在Up方法中添加SQL函数,方法如下

public partial class your_migration_name : Migration {

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.Sql(@"<YourQuery>");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.Sql(@"Drop <YourQuery>");
}
}
  1. 运行 Update-Database 在程序包管理器控制台中。