Search code examples
postgresqlentity-framework-coreef-code-firstef-fluent-api

Hash Index on Pgsql table in EFCore


How can I specify the index type as "hash" for pgsql db in Efcore fluent api?

Eg:

modelBuilder.Entity().HasIndex(u => u.PId).IsUnique();

Is there any extension method specific to pgsql that accepts the index type? The default index type being created is 'btree'.


Solution

  • you can use the HasMethod like this:

    modelBuilder.Entity().HasIndex(u => u.PId).HasMethod("hash")
    

    the method according to postgres documentation

    method

    The name of the index method to be used. Choices are btree, hash, gist, spgist, gin, and brin. The default method is btree.