Does NHibernate LINQ support ToLower() in Where() clauses?

不羁岁月 提交于 2019-11-30 17:31:56

I had this happen recently. I can tell you that ToLower() does not work and that Contains() and StartsWith() do work and are not case sensitive. You can get the desired affect by using Contains() and StartsWith() directly.

Diego Mijelshon

There seems to be a lot of confusion around this subject.

  • The "old" Linq provider (for NHibernate 2.x) probably might not support this. If that's the case, it never will because it's not maintained anymore.
  • The new provider (included with NHibernate 3.x) does support it (although ToUpper and ToLower seem to be inverted, see http://groups.google.com/group/nhibernate-development/browse_thread/thread/a167216e466b3241)
  • Contains and StartsWith map to the LIKE operator in SQL. They are not case insensitive themselves; it's the collation that makes them case insensitive, so that depends on how your column/schema were created.

Update (2010-04-09): bug confirmed and patch submitted, see https://nhibernate.jira.com/browse/NH-2169

Update (2010-05-21): patch was applied on 2010-05-01 and works as expected now.

According to the comments in these two blog posts this functionality is not implemented yet.

You might want to confirm whether the database uses case sensitivity.

If it doesn't, then you don't need .ToLower()

The accepted answer mentions using Contains() and StartsWith() which are good. but wouldn't work in cases when you want to be sure both strings are the same.

Using "==" will suffice since it is also case-insensitive. So, you no longer need to use ToLower() nor ToUpper();

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