How to implement limit with Nhibernate and Sybase -
we use nhibernate 3.3 connect our sybase ase 15 database. fine except non support of limit (or top). implemented in sybase not in nhibernate. have solution?
i tried create customsybasease15dialect change this:
public override bool supportslimitoffset { { return true; } } public override sqlstring getlimitstring(sqlstring sql, sqlstring offset, sqlstring limit) { int insertionpoint = getafterselectinsertpoint(sql); if (insertionpoint > 0) { sqlstringbuilder limitbuilder = new sqlstringbuilder(); limitbuilder.add("select"); if (insertionpoint > 6) { limitbuilder.add(" distinct "); } limitbuilder.add(" top "); limitbuilder.add(limit); if (offset != null) { limitbuilder.add(" start @ "); limitbuilder.add(offset); } limitbuilder.add(sql.substring(insertionpoint)); return limitbuilder.tosqlstring(); } else { return sql; // unchanged } } /// <summary> /// copied mssql2000dialect. /// </summary> private int getafterselectinsertpoint(sqlstring sql) { if (sql.startswithcaseinsensitive("select distinct")) { return 15; } if (sql.startswithcaseinsensitive("select")) { return 6; } throw new notsupportedexception("the query should start 'select' or 'select distinct'"); } using linq2nhibernate syntax, works
session.query<product>().first() limit correctly set 1 if this
session.query<product>().take(3).tolist() limit set "?".
what can do?
as mentioned in previous comment there bug in nhibernate. fixed not yet included in official version.
https://nhibernate.jira.com/browse/nh-3281
you can download main source , build dll manually https://github.com/nhibernate/nhibernate-core .
michael
Comments
Post a Comment