EF4 Linq Oracle11g 使查询不区分大小写
我们正在转向 EF4 和 EF4 Linq 作为 Oracle 11g 数据库的数据库接口。数据库设置为区分大小写,但我们需要不区分大小写进行搜索。在 Oracle 中,在查询中使用“UPPER”可能会非常昂贵。我已经查看了以下选项以及所指示的结果:
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
-----------------------
结果本身就说明了一切,除了最后一个示例实际上可能会丢失记录。
大家对于技术还有其他的想法吗?
谢谢,萨默尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更改数据库元数据中的列排序规则或在查询中指定它。在 EF 的查询中指定它的唯一方法是使用 ESQL 或查询生成器方法。更好的想法是更改数据库列本身的排序规则。
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.