Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate ORDER BY CURRENT_TIMESTAMP conflicts with DISTINCT

Could anybody please explain why NHibernate on MsSql2012Dialect generates query that can not be processed by server? It builds query this way when there is no sorting specified explicitly.

...
ORDER BY CURRENT_TIMESTAMP
OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY 
like image 709
pavel Avatar asked Jan 13 '16 11:01

pavel


1 Answers

This is unresolved bug registered in jira, based on the suggestions, this is my work around:

public class MyMsSql2012Dialect : MsSql2012Dialect
{
    public override SqlString GetLimitString(SqlString querySqlString, SqlString offset, SqlString limit)
    {
        var result = base.GetLimitString(querySqlString, offset, limit);

        return result.Replace("ORDER BY CURRENT_TIMESTAMP", "ORDER BY 1");
    }
}
like image 153
Najera Avatar answered Sep 28 '22 11:09

Najera