Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create unique index case insensitive at entity framework core 2.1

I use npqsql 4+ and efcore 2.1+, how I can create unique invariant case insensetive constraint on field?

The following construction doesn't work:

modelBuilder.Entity<Company>().HasAlternateKey(city => city.Name.ToUpperInvariant());
like image 997
AuthorProxy Avatar asked Aug 30 '25 16:08

AuthorProxy


1 Answers

Unfortunately, there doesn't appear to be a way to create an index with a specific collation using the Npgsql driver. The only PostgreSQL specific configuration that can be done on an index is to set the method using the ForNpgsqlHasMethod extension. You have a couple of options:

  1. Create/modify the index with some SQL, perhaps as part of a migration
  2. Go an request the feature on the official Github project, or even write your own and submit a pull request!
like image 78
DavidG Avatar answered Sep 02 '25 10:09

DavidG