Skip to content

Instantly share code, notes, and snippets.

@dontpaniclabsgists
Last active August 28, 2017 13:57
Show Gist options
  • Save dontpaniclabsgists/a6dcf3323f24bdb8cdb97c48aa4b7693 to your computer and use it in GitHub Desktop.
Save dontpaniclabsgists/a6dcf3323f24bdb8cdb97c48aa4b7693 to your computer and use it in GitHub Desktop.
Cosmos2_7
public async Task<PageResult> Page(string token, int pageSize, string customerId)
{
using (var client = new DocumentClient(new Uri(_endpoint), _key))
{
var link = UriFactory.CreateDocumentCollectionUri(_databaseId, CollectionId);
var querySetup = client.CreateDocumentQuery<Note>(
link,
new FeedOptions()
{
MaxItemCount = pageSize,
RequestContinuation = token,
PartitionKey = new Microsoft.Azure.Documents.PartitionKey(customerId)
});
var query = querySetup.AsDocumentQuery();
var result = new PageResult()
{ HasMore = false };
var list = new List<Note>();
if (query.HasMoreResults)
{
var note = await query.ExecuteNextAsync<Note>();
result.Token = note.ResponseContinuation;
if (!string.IsNullOrWhiteSpace(result.Token))
result.HasMore = true;
list.AddRange(note);
}
result.Notes = list.ToArray();
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment