NHibernate 2nd lvl cache, custom query, sqldialect

前端 未结 7 1070
遥遥无期
遥遥无期 2020-12-21 06:59

I got trunk version of NH and FNH. When i try to add 2nd level cache, some parts of NHibernate forgets about chosen sqldialect.


Initial configuration:

7条回答
  •  旧时难觅i
    2020-12-21 07:42

    We ran into this issue when upgrading to NHibernate version 3.3, but for a different reason...whitespace. We had a lot of sql strings that looked like this:

    var sql = @"
    select col1 from MyTable";
    

    or:

    var sql = @" select col1 from My Table";
    

    These resulted in the "The query should start with 'SELECT' or 'SELECT DISTINCT'" errors because NHibernate doesn't trim the string before validating it.

    We created a new dialect that trims the string first to get around this:

    public class Sql2008DialectCustom : MsSql2008Dialect
    {
      public override SqlString GetLimitString(SqlString queryString, SqlString offset, SqlString limit)
      {
        var trimmedQueryString = queryString.Trim();
        return base.GetLimitString(trimmedQueryString, offset, limit);
      }
    }
    

提交回复
热议问题