If you're using EF Core 5.0, then see below (probably the better solution). Otherwise, I added a case insensitive check by making use of the citext extension as described here. There are some limitations, I won't list them here but you can read up on them in the previous link or directly on the PostgreSQL Docs.
Also ensure you have the postgres-contrib package installed to make use of this extension.
First, enable the extension by adding it to your model builder
modelBuilder.HasPostgresExtension("citext");
Then use the citext as the column type
builder.Property(s => s.Name)
.HasColumnType("citext")
EF Core 5.0
With EF Core 5.0 there's better support by making use of Collations. You can also check out the Npgsql docs in regards to PostrgeSQL. This gets over a bunch of limitations with citext above and gives you a lot more control.
So the (untested) steps are:
- Create a collation as a database object using ICU. This will create a non-deterministic, case-insensitive ICU collation. If you need something else, check out the ICU docs.
modelBuilder.HasCollation("case_insensitive_collation", locale: "en-u-ks-primary", provider: "icu", deterministic: false);
- Now on you column, you can add:
builder.HasIndex(s => s.Name)
.UseCollation("case_insensitive_collation")
.IsUnique();
If you achieved it some other way, I'd love to hear how.