Make Entity Framework be case-insensitive

有些话、适合烂在心里 提交于 2019-12-07 04:02:54

问题


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("strigToCompare")

it doesn't have an overload.


回答1:


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.



来源:https://stackoverflow.com/questions/3069241/make-entity-framework-be-case-insensitive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!