可以在 CodeFirst EntityFramework 中使用 NPGSQL 指定 JSONB GIN 索引吗?

Bob*_*Bob 3 postgresql entity-framework npgsql

我在 EFCore 项目中的 EF 代码优先对象上有一些 JSONB 列。我想为那些存储为 JSONB 属性/列的强类型对象内的属性设置一些 GIN 索引。
这可能吗?(目前使用 postgres:latest image)

谢谢。

Sam*_*Sch 5

由于.ForNpgsqlHasMethod("gin")已过时,因此您可以使用 EF Core 3.1:

metaBuilder
    .HasIndex(x => x.DocumentNumber)
    .HasMethod("gin")
    .HasOperators("gin_trgm_ops");
Run Code Online (Sandbox Code Playgroud)

您的迁移将如下所示:

migrationBuilder.CreateIndex(
    name: "IX_DocumentContentMeta_DocumentNumber",
    table: "DocumentContentMeta",
    column: "DocumentNumber")
    .Annotation("Npgsql:IndexMethod", "gin")
    .Annotation("Npgsql:IndexOperators", new[] { "gin_trgm_ops" });
Run Code Online (Sandbox Code Playgroud)