Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit data query and get only last 1000 rows

I am using linq to nhibernate to query data from large table. I am trying to limit my data query and get only last 1000 rows and only then make filtering, sorting and pagin.

When i try to use .Take() i got an error:

unable to locate HQL query plan in cache; generating (.Count[X4Data.Entity.IEventView](.OrderBy[X4Data.Entity.IEventView,System.DateTime](.Take[X4Data.Entity.IEventView](.Where[X4Data.Entity.IEventView](NHibernate.Linq.NhQueryable`1[X4Data.Entity.IEventView], Quote((x, ) => (Equal(x.DeviceId, p1))), ), p2, ), Quote((c5d4d87c-87ba-4e91-9652-bcdc87e3f0ba, ) => (c5d4d87c-87ba-4e91-9652-bcdc87e3f0ba.AtmTime)), ), ))

My code:

query = query.Take(rowCount);
query = query.ApplyFiltering(cmd, binder);
query = query.ApplySorting(cmd, binder);
binder.TotalCount = query.Count();
query = query.ApplyPaging(cmd);

Thanks a lot and sorry for my bad english

like image 899
AleGO Avatar asked May 22 '12 13:05

AleGO


1 Answers

Try:

query.OrderByDescending(criteria).Take(rowCount).OrderBy(criteria)
like image 60
mellamokb Avatar answered Sep 29 '22 09:09

mellamokb