Hi
I am fairly new to NHibernate so this is definitely a noob question. I am running NHibernate 1.2.1 with SQL Server 2005.
I am trying to get the TOP 100 rows from my purchase table. Below is a snippet of the code:
Code:
IQuery query = session.CreateQuery("from Purchase p order by p.Date DESC");
query.SetMaxResults(100);
IList<Purchase> purchases = query.List<Purchase>();
The SQL I would expect would be something like:
Code:
SELECT TOP 100 p.PurchaseID,
p.PlayerID,
p.CasinoID,
p.PurchaseStatus,
p.PurchaseBrandID,
p.Date,
p.Amount
FROM tb_Purchase p
ORDER BY p.Date DESC
Instead, the SQL that is being generated is
Code:
SELECT TOP 100 PurchaseID6_, Purchase2_6_, Date6_, Amount6_, CasinoID6_, PlayerID6_, Purchase7_6_
FROM (SELECT ROW_NUMBER() OVER(ORDER BY __hibernate_sort_expr_1__ DESC) as row, query.PurchaseID6_, query.Purchase2_6_, query.Date6_, query.Amount6_, query.CasinoID6_, query.PlayerID6_, query.Purchase7_6_, query.__hibernate_sort_expr_1__
FROM (select purchase0_.PurchaseID as PurchaseID6_, purchase0_.PurchaseStatus as Purchase2_6_, purchase0_.Date as Date6_, purchase0_.Amount as Amount6_, purchase0_.CasinoID as CasinoID6_, purchase0_.PlayerID as PlayerID6_, purchase0_.PurchaseBrandID as Purchase7_6_, purchase0_.Date as __hibernate_sort_expr_1__
from tb_Purchase purchase0_) query
) page
WHERE page.row > 0 ORDER BY __hibernate_sort_expr_1__ DESC
Is there a way to tell Nhibernate that I do not want to page and therefore it should simplify the query? Possibly I am not using the correct methods here?
Any help will be greatly appreciated
Thanks
Craig