开发者

Make Entity Framework be case-insensitive

开发者 https://www.devze.com 2023-01-04 02:59 出处:网络
Is it possible to set entity framework string comparison case insensitive by default? If I use string.StartsWith(\"stringToCompare\", StringComparison.CurrentCultureIgnoreCase)

Is it possible to set entity framework string comparison case insensitive by default?

If I use

string.StartsWith("stringToCompare", StringComparison.CurrentCultureIgnoreCase)

it works. But when I need to use

string.Contains("stri开发者_如何学PythongToCompare")

it doesn't have an overload.


You can simply change the case of both fields to Upper Case:

String stringToCompare = "Some String";

string.ToUpper().Contains(stringToCompare.ToUpper())

This will make the search case-insensitive by converting all case to upper. Of course, ToLower() would work as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消