views:

115

answers:

1

Is there any example code someone can show me that will page through data in a given table, and use CTE's under the hood?

Is nhibernate suppose to work across various databases out of the box? I am using MS SQL Server 2008 now, but what if the client wants to use Oracle someday?

+2  A: 

For paging you just define start and end result in the query:

IQuery q = sess.CreateQuery("from DomesticCat cat");
q.SetFirstResult(20);
q.SetMaxResults(10);
IList cats = q.List();

See the reference docs

NHibernate is supposed to work across various databases. Many dialects are implemented and available out of the box. SqlServer and Oracle are both very well supported.

See the reference docs for a list of supported dialects.

Stefan Steinegger
The way Stefan shows would be the best. I have no clue why you involve Common Table Expressions in the questions, there's no need for that.
Rune Sundling
Rune, CTE's would be more effecient. Stefan, what does the sql look like?
Blankman
Try it, I can't tell you by heart, it looks rather complicated. But it uses SQL features from the underlying dbms.
Stefan Steinegger