EF Core中如何设置Gin索引?
https://stackoverflow.com/questions/54618858/can-jsonb-gin-indexes-be-specified-in-codefirst-entityframework-with-npgsql
Since .ForNpgsqlHasMethod(“gin”) is obsolete, with EF Core 3.1 you can use this:
1 2 3 4
| metaBuilder .HasIndex(x => x.DocumentNumber) .HasMethod("gin") .HasOperators("gin_trgm_ops");
|
and your migration will look like this:
1 2 3 4 5 6
| 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
1 2 3 4 5 6 7 8
| 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:
1
| CREATE INDEX ix_artist_album ON artist USING gin ("album");
|
Documentation in Npgsql: http://www.npgsql.org/efcore/modeling/indexes.html