简体   繁体   English

使用Azure移动服务C#后端进行分页和排序

[英]Paging & Sorting with Azure Mobile Services C# Backend

What's wrong with the following code? 以下代码有什么问题?

 int skipCount = pageIndex * 20;
 var query = questionsTable.Where(x => x.AskedAtCityId == city.Id).OrderByDescending(x => x.AskedAt).Take(20).Skip(skipCount);
 query.IncludeTotalCount(); 

 await query.ToListAsync().ContinueWith(t =>
 {
     if (t.Status == TaskStatus.RanToCompletion)
     {
         tcs.SetResult(t.Result);
     }
 });

I intend to get some data that is sorted, filtered & paged. 我打算获取一些经过排序,过滤和分页的数据。 The result set I get is filtered fine, but it's not sorted by createdAt date. 我得到的结果集被很好地过滤,但是没有按createdAt日期排序。

Firing the query a second time even jumbles up the data & also the data is not continuous. 第二次触发查询会弄乱数据,并且数据也不连续。 I am getting all random results. 我得到所有随机结果。

What I need is a list of most recently asked questions, sorted by date, descending & in pages of 20 records. 我需要的是最新问题列表,按日期,降序和20条记录的页面排序。

What's missing? 缺少了什么?

Thanks 谢谢

The query is just fine. 查询很好。 I did make a small change though. 我确实做了一点零钱。 Skip() first & then Take() Also I was getting the jumbled up records because the index I was sending as a parameter had a miscalculated value in it. 首先跳过(),然后再获取()。另外,我也得到了混乱的记录,因为作为参数发送的索引中包含错误计算的值。 Fixing that bit of code & now everything is just fine. 修复那段代码,现在一切都很好。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM