I have a project where I use Entity Framework Core and PostgreSQL. In this project, I want to query for string types with case insensitivity. How can I do that?
Here is my DbContext
methods:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasCollation("my_collation", locale: "en-u-ks-primary", provider: "icu", deterministic: true);
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
base.OnModelCreating(modelBuilder);
SeedDatabase(modelBuilder);
}
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.Properties<string>().UseCollation("my_collation");
}
Here are my query samples:
var b = await _uow.SysHistoryRepository.FirstOrDefaultAsync(x => x.TableName.Contains("Sirket"));
var a = await _uow.SysHistoryRepository.FirstOrDefaultAsync(x => x.TableName.Contains("sirket"));
It works in the like query in PostgresSql, but I get the error I specified in EF Core.
The error message that is returned while querying:
Npgsql.PostgresException: '0A000: nondeterministic collations are not supported for substring searches'