AuthorProxy
AuthorProxy

Reputation: 8047

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());

Upvotes: 4

Views: 1662

Answers (2)

Scott
Scott

Reputation: 1

Change to always save the City Name as uppercase

Upvotes: 0

DavidG
DavidG

Reputation: 118937

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!

Upvotes: 3

Related Questions