【问题标题】:Custom Entity Framework Core Migration Script?自定义实体框架核心迁移脚本?
【发布时间】:2018-12-05 12:12:11
【问题描述】:

我需要进行“全文索引”,但我使用的是 ef core 2.1 代码优先迁移,但完整索引在核心中没有一流的支持。

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

【问题讨论】:

标签: entity-framework ef-code-first entity-framework-core entity-framework-migrations


【解决方案1】:

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

  1. 通过在包中运行 Add-Migration 命令创建空迁移 经理控制台。
  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

【讨论】:

    猜你喜欢
    • 2020-06-21
    • 2021-06-27
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-06
    • 2019-11-08
    • 2022-01-28
    相关资源
    最近更新 更多