0

I'd like to escape the queries that nhibernate generates when I use Contains.
I mean, supposing that I'm using SQL Server Contains("%"), NHibernate should generate like '[%]'.

I'd like to obtain this without using a different extension method (i.e. implementing and using MyOwnContain). In this case the answer could be this:
Linq to NHibernate extensibility for custom string query operations?

Community
  • 1
  • 1
bubi
  • 6,414
  • 3
  • 28
  • 45

1 Answers1

1

Not possible with currently available versions of NHibernate, though the upcoming NH 4.1 will fix at least one of these relevant issues:

https://nhibernate.jira.com/browse/NH-3726 (escape for Like())

https://nhibernate.jira.com/browse/NH-3829 (escape for Contains(), etc.)

However, since the % wildcard can be disabled in your case by enclosing it in brackets, you should be able to do this yourself before calling Contains(). Just beware and prepare to handle the situation when the above is eventually implemented in NH.

Oskar Berggren
  • 5,583
  • 1
  • 19
  • 36