EF Core 3.0 translating string.Equals ordinalIgnoreCase correctly

c# ef-core-3.0 entity-framework-core

Question

Before EF Core 3.0 this worked fine (evaluated on server+client):

var exists = await _context.Countries.AsNoTracking().AnyAsync(x => x.CountryCode.Equals(country.CountryCode, StringComparison.OrdinalIgnoreCase));

What is the best/preferred method to translate the string.Equals(str, StringComparison.OrdinalIgnoreCase)-part now in EF Core 3.0, so that the query evaluates only on the server side.

var exists = await _context.Countries.AsNoTracking().AnyAsync(x => x.CountryCode.ToUpper() == country.CountryCode.ToUpper());

or

var exists = await _context.Countries.AsNoTracking().AnyAsync(x => x.CountryCode.ToLower() == country.CountryCode.ToLower());

or

var exists = await _context.Countries.AsNoTracking().AnyAsync(x => x.CountryCode.ToUpperInvariant() == country.CountryCode.ToUpperInvariant());

or

var exists = await _context.Countries.AsNoTracking().AnyAsync(x => x.CountryCode.ToLowerInvariant() == country.CountryCode.ToLowerInvariant());

or something else?

1
2
10/31/2019 10:23:49 AM

Accepted Answer

You should not do that, nor use the accepted answer method, you should just use String.Equals() without parameters and configure your database collation, during creation or migration.

4
10/31/2019 11:08:00 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow