1

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'

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Not specific to EF core but maybe it helps -> https://dba.stackexchange.com/questions/266097/postgresql-nondeterministic-collations-are-not-supported-for-like – panoskarajohn Apr 24 '23 at 09:07
  • Might be duplicate -> https://stackoverflow.com/questions/66084881/ef-core-postgresql-string-compare-case-insensitive – panoskarajohn Apr 24 '23 at 09:08

0 Answers0