How to load Trigram tokenizer for sqlite using EF core?

346 Views Asked by At

I am using Microsoft.EntityFrameworkCore 3.1.8 with my UWP app.

I need to run this sqlite query using Entity framework core and Code first approach:

CREATE VIRTUAL TABLE TrialFTS USING fts5(search, tokenize="trigram");

This gets executed in sqlite database directly without any errors and works fine.

But when I use it inside the migration:

public partial class FTSFirstMigration : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql("CREATE VIRTUAL TABLE ProductFTS USING fts5(search, tokenize=\"trigram\");");          
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ProductFTS");
        }
    }

It fails and throws the error: SQLite Error 1: 'no such tokenizer: trigram'

How to solve this? How to load this tokenizer module explicitly to the sqlite database?

1

There are 1 best solutions below

2
Andrea B. On

As reported here the tokenizer was added in Sqlite 3.34.0 on 2020-12-01.

You can check which version you are currently using with

select sqlite_version();