'Case Insensitive Index mapping in EF Core

Is it possible to create a case insensitive unique index in Entity Framework core using Fluent API?

For example, a case insensitive unique index can be defined in Oracle using the following SQL:

create unique index test on "Person"(lower("Name"));

However, as far as I'm aware the only option in EF Core is a case sensitive unique constraint, such as:

builder.HasIndex(e => e.Name)
            .IsUnique();

I have tried the following but it doesn't work:

builder.HasIndex(e => e.Name.ToLower())
            .IsUnique();


Solution 1:[1]

From EF Core 5.0, you can use collations.

builder.Property(e => e.name).UseCollation("SQL_Latin1_General_CP1_CI_AS");
builder.HasIndex(e => e.name).IsUnique();

For oracle, you might want to try a different collation name, like BINARY_CI.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Degravef