I've got some JSONB columns on my EF code first objects in an EFCore project. I would like to set up some GIN indexes to properties inside those strongly typed objects being stored as JSONB property/column.
Is this possible? (currently using the postgres:latest image)
Thanks.
Since .ForNpgsqlHasMethod("gin")
is obsolete, with EF Core 3.1 you can use this:
metaBuilder
.HasIndex(x => x.DocumentNumber)
.HasMethod("gin")
.HasOperators("gin_trgm_ops");
and your migration will look like this:
migrationBuilder.CreateIndex(
name: "IX_DocumentContentMeta_DocumentNumber",
table: "DocumentContentMeta",
column: "DocumentNumber")
.Annotation("Npgsql:IndexMethod", "gin")
.Annotation("Npgsql:IndexOperators", new[] { "gin_trgm_ops" });
Well, actually u can do it like this
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Artist>()
.HasIndex(a => new { a.Album })
.ForNpgsqlHasMethod("gin");
base.OnModelCreating(modelBuilder);
}
and when u run ef add migration, the sql query generated will be like:
CREATE INDEX ix_artist_album ON artist USING gin ("album");
Documentation in Npgsql: http://www.npgsql.org/efcore/modeling/indexes.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With