English 中文(简体)
限制数据查询并只获得最后1000行数据查询
原标题:Limit data query and get only last 1000 rows

我正使用 linq 到 nhiberate 从大表格查询数据。 我正试图限制我的数据查询, 仅获取最后1000 行, 然后再进行过滤、 排序和 pagin 。

当我试图使用. takee() 我有一个错误:

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)), ), ))

我的代码:

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

非常感谢,为我的坏英语感到抱歉

最佳回答

尝试 :

query.OrderByDescending(criteria).Take(rowCount).OrderBy(criteria)
问题回答

您可以使用此功能:

list.Skip(Math.Max(0, list.Count() - N)).Take(N);

<强 > 示例:

在此创建列表, 包含9999 个值, 并通过 < strong> LIN_ @ / strong > 选择最后的1000 个值 。

 List<int> list = new List<int>();
        for (int i = 0; i < 9999; i++)
        {
            list.Add(i);
        }
        int take = 1000;
        var result = list.Skip(Math.Max(0, list.Count() - take)).Take(take);

using ICriteria try this:

    criteria.SetMaxResults(1000);
    criteria.AddOrder(Order.Desc("ID"));




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签