我正在尝试对Cosmos db进行分页,但是skip命令出了点问题。
var resultDTO = this.client.CreateDocumentQuery<AuditDTO>(
UriFactory.CreateDocumentCollectionUri(idDatabase, idCollection), queryOptions)
.Skip(2*1)
.Take(amount)
.AsEnumerable()
.ToList();
您知道如何实现吗?
答案 0 :(得分:2)
当前,支持分页并且它基于continuation token.
以下示例说明了一种根据所需的页码,页面大小和连续标记查询文档的方法:
private static async Task<KeyValuePair<string, IEnumerable<CeleryTask>>> QueryCosmosDBPage(int pageNumber, int pageSize, string continuationToken)
{
DocumentClient documentClient = new DocumentClient(new Uri("https://{CosmosDB/SQL Account Name}.documents.azure.com:443/"), "{CosmosDB/SQL Account Key}");
var feedOptions = new FeedOptions {
MaxItemCount = pageSize,
EnableCrossPartitionQuery = true,
// IMPORTANT: Set the continuation token (NULL for the first ever request/page)
RequestContinuation = continuationToken
};
IQueryable<CeleryTask> filter = documentClient.CreateDocumentQuery<CeleryTask>("dbs/{Database Name}/colls/{Collection Name}", feedOptions);
IDocumentQuery<CeleryTask> query = filter.AsDocumentQuery();
FeedResponse<CeleryTask> feedRespose = await query.ExecuteNextAsync<CeleryTask>();
List<CeleryTask> documents = new List<CeleryTask>();
foreach (CeleryTask t in feedRespose)
{
documents.Add(t);
}
return new KeyValuePair<string, IEnumerable<CeleryTask>>(feedRespose.ResponseContinuation, documents);
}
答案 1 :(得分:1)