2

I need to make a "full-text indexed" but I am using ef core 2.1 code first migration, but Full Indexes do not have first class support in core.

How can I write my own migration that would be applied while the other generated migrations are being applied?

4
  • migrationBuilder.Sql method is your friend. For more info, see Migrations and API Reference. Commented Jun 26, 2018 at 17:38
  • So, I generate the migration file then go in and manually change it or do I make a another file? Commented Jun 26, 2018 at 17:40
  • Manually change it. Your use-case with Full-Text Search is even mentioned in the Empty Migrations part of the first documentation link. Commented Jun 26, 2018 at 17:42
  • This was answered in your Github issue Full Text Search in EF Core 2.1 and an example was provided your in SO question How to use FreeText in EF core 2.1. Commented Jun 27, 2018 at 1:26

1 Answer 1

5

You have to create empty migration and then in Up method you can write your SQL query.

  1. Create Empty Migration by running Add-Migration command in Package Manager Console.
  2. Add the SQL function in Up method like the following way.

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. Run Update-Database in Package Manager Console.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.