积极答复者
Mobile App应用服务后端如何修改每次请求返回的50条,Node.js

问题
答案
-
Hi liguo1976,
默认情况下,查询移动应用后端的数据是采用分页的形式来返回数据的,分页可以防止大型数据集发出的默认请求对服务造成负面影响。我们可以通过调用 Take 方法增加返回的行数,与 Skip 方法一起使用可以请求查询返回的总数据集的特定“页”。
对于读取最新的数据,如您在插入数据时指定了特定的 ID,则可以使用该 ID 获取该消息:
// This query filters out the item with the ID of 37BBF396-11F0-4B39-85C8-B319C729AF6D TodoItem item = await todoTable.LookupAsync("37BBF396-11F0-4B39-85C8-B319C729AF6D");
若未指定 ID, 则您可以使用 IncludeTotalCount 方法请求应该返回所有记录的总计数,然后通过 Take 和 Skip 方法找到最新插入的数据。
// query table to include the total row count
MobileServiceTableQuery<TodoItem> query = todoTable.todoTable.Take(0).IncludeTotalCount(); var results = await query.ToEnumerableAsync(); // get the row count long count = (IQueryResultEnumerable<TodoItem>)results).TotalCount;
// return newest 100 items
int bufferSize = 100;
if (results != null && count > 0) {
// skips all the previous items and returns the newest 100 items.
query = todoTable.Skip(count-bufferSize).Take(bufferSize);
List<TodoItem> items = await query.ToListAsync();}
详细内容请参考文档:如何查询移动应用中的数据。
MSDN 社区技术支持
如果该回复解决了您的问题,请及时点击“标记为答案”选项,如未解决请选择“取消标记为答案”,这会有利于其他人员来阅读您的帖子。如果您对MSDN 技术支持有任何的建议或意见,请随时联系 MSDNFSF@microsoft.com。
- 已标记为答案 liguo1976 2017年6月20日 3:23
- 已编辑 David TangMicrosoft contingent staff, Moderator 2017年6月20日 5:36 Change ITotalCountProvider TO IQueryResultEnumerable
全部回复
-
Hi liguo1976,
默认情况下,查询移动应用后端的数据是采用分页的形式来返回数据的,分页可以防止大型数据集发出的默认请求对服务造成负面影响。我们可以通过调用 Take 方法增加返回的行数,与 Skip 方法一起使用可以请求查询返回的总数据集的特定“页”。
对于读取最新的数据,如您在插入数据时指定了特定的 ID,则可以使用该 ID 获取该消息:
// This query filters out the item with the ID of 37BBF396-11F0-4B39-85C8-B319C729AF6D TodoItem item = await todoTable.LookupAsync("37BBF396-11F0-4B39-85C8-B319C729AF6D");
若未指定 ID, 则您可以使用 IncludeTotalCount 方法请求应该返回所有记录的总计数,然后通过 Take 和 Skip 方法找到最新插入的数据。
// query table to include the total row count
MobileServiceTableQuery<TodoItem> query = todoTable.todoTable.Take(0).IncludeTotalCount(); var results = await query.ToEnumerableAsync(); // get the row count long count = (IQueryResultEnumerable<TodoItem>)results).TotalCount;
// return newest 100 items
int bufferSize = 100;
if (results != null && count > 0) {
// skips all the previous items and returns the newest 100 items.
query = todoTable.Skip(count-bufferSize).Take(bufferSize);
List<TodoItem> items = await query.ToListAsync();}
详细内容请参考文档:如何查询移动应用中的数据。
MSDN 社区技术支持
如果该回复解决了您的问题,请及时点击“标记为答案”选项,如未解决请选择“取消标记为答案”,这会有利于其他人员来阅读您的帖子。如果您对MSDN 技术支持有任何的建议或意见,请随时联系 MSDNFSF@microsoft.com。
- 已标记为答案 liguo1976 2017年6月20日 3:23
- 已编辑 David TangMicrosoft contingent staff, Moderator 2017年6月20日 5:36 Change ITotalCountProvider TO IQueryResultEnumerable
-
谢谢,确实如您所说,我已经更新了回复。
MSDN 社区技术支持
如果该回复解决了您的问题,请及时点击“标记为答案”选项,如未解决请选择“取消标记为答案”,这会有利于其他人员来阅读您的帖子。如果您对MSDN 技术支持有任何的建议或意见,请随时联系 MSDNFSF@microsoft.com。