1

I'm using NHibernate 3.1 with SQL CE 4 (Using the MsSqlCe40Dialect). Using Linq to produce queries.

If I use String.Contains, String.StartsWith or String.EndsWith, invalid SQL is produced.

For example:

Session.Query<User>.Where(user => user.Name.Contains("Joe"))

produces SQL like this:

SELECT Name FROM User WHERE (User.Name like ('%'||@p0||'%'))

This is somewhat simplified from the actual SQL produced, but the problem is in the extra '||...||'

I expect this is a problem with the SQL CE dialect, but I'm not sure where to go from here. Any ideas for a fix / workaround?

3
  • Can you use HQL for this particular case? Commented May 9, 2012 at 23:23
  • This is actually part of a larger query. I'd like to keep it just Linq if possible. Are you aware of any way to combine Linq with HQL or criteria? Commented May 10, 2012 at 1:17
  • write the entire thing using HQL? Commented May 10, 2012 at 17:39

1 Answer 1

1

Looks like this was fixed shortly after the 3.1 release (in this commit). Unfortunately, I cannot upgrade NHibernate due to other dependencies. In the meantime, I have worked around the problem by subclassing MsSqlCe40Dialect with the following code:

using NHibernate;
using NHibernate.Dialect;
using NHibernate.Dialect.Function;

namespace DataAccess
{
    public class CustomMsSqlCe40Dialect : MsSqlCe40Dialect
    {
        public CustomMsSqlCe40Dialect ()
        {
            RegisterFunction("concat", new VarArgsSQLFunction(NHibernateUtil.String, "(", "+", ")"));
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.