I am creating a new NHibernate dialect to work with an OpenEdge 10.2a database over ODBC. I have been using the dialect in NHibernate 2.1 with no problems, but when porting it to NHibernate 3.3.1 I’m having problems with the generated querys Like statement.
When using the dialect on NHibernate 3.3.1, like statements are generated like below for a linq query using startswith(“sometest”).
select test from tests
where testname like (?||'%');
p0 = 'sometest' [Type: String (8)]
This has changed since NHibernate 2.1, and the OpenEdge database does not support this. The same query in NHibernate 2.1 looks like:
select test from tests
where testname like ?;
p0 = 'sometest%'
I have tried using the MsSql2005Dialect, and this changes the generated SQL a little to:
select test from tests
where testname like (?+'%');
p0 = 'sometest' [Type: String (8)]
Notice the pipes that became a plus.
What causes these changes, and how can I affect it so I can can make my dialect work on NH 3.3.1?
Unfortunately, this will not work out of the box for databases that do not support concat expressions as LIKE parameters. See NH-2254
The workaround is to extend the LINQ provider. Here’s a sample.