EF Core 3.0翻译字符串。正确等于ordinalIgnoreCase [英] EF Core 3.0 translating string.Equals ordinalIgnoreCase correctly

查看:138
本文介绍了EF Core 3.0翻译字符串。正确等于ordinalIgnoreCase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在EF Core 3.0之前,此方法运行良好(在服务器+客户端上评估):

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));

翻译字符串的最佳/首选方法是什么? ,StringComparison.OrdinalIgnoreCase)-现已在EF Core 3.0中提供,因此查询仅在服务器端进行评估。

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());

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

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

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

还是其他?

推荐答案

您不应该这样做,也不要使用公认的答案方法,您应该只使用不带参数的String.Equals()并在创建或迁移期间配置数据库排序规则。

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.

这篇关于EF Core 3.0翻译字符串。正确等于ordinalIgnoreCase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆