EF4 Linq Oracle11g making queries none case-sensitive

吃可爱长大的小学妹 提交于 2020-01-06 07:19:33

问题


We are moving to EF4 & Linq as our db interface to a Oracle 11g db. The database is setup as case sensitive, but we need to search as case insensitive. In oracle using "UPPER" in the query is potentially very expensive. I have looked at the following options with the indicated results:

ChangeEntities.TABLE.Where(x => x.FIELD.Equals(VARIABLE))

generates SQL Where clause:

WHERE TABLE.FIELD = VARIABLE
---------------------
ChangeEntities.TABLE.Where(x => x.FIELD.Equals(VARIABLE.ToUpper()))

generates SQL Where clause:

WHERE TABLE.FIELD = (UPPER(VARIABLE))
---------------------
ChangeEntities.TABLE.Where(x => x.FIELD.ToUpper().Equals(VARIABLE.ToUpper()));

generates SQL Where clause:

WHERE (UPPER(TABLE.FIELD)) = (UPPER(VARIABLE))
---------------------
ChangeEntities.TABLE.Where(x => x.FIELD.Equals(VARIABLE, StringComparison.CurrentCultureIgnoreCase))

generates SQL Where clause:

WHERE TABLE.FIELD = VARIABLE
-----------------------

The results kinda speak for themselves, except that the last example could actually miss records.

Does anyone have any other thoughts on techniques?

Thanks, Sammer


回答1:


You need to either change the column collation in DB metadata or specify it in the query. The only way to specify it in a query in EF is to use ESQL or Query Builder methods. A better idea is to change the collation on the DB column itself.



来源:https://stackoverflow.com/questions/4763182/ef4-linq-oracle11g-making-queries-none-case-sensitive

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