Skip to content

Instantly share code, notes, and snippets.

@EricAtMSFT
Last active March 15, 2016 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricAtMSFT/221b1cabbe3178be07f5 to your computer and use it in GitHub Desktop.
Save EricAtMSFT/221b1cabbe3178be07f5 to your computer and use it in GitHub Desktop.
DocumentDB query using simple lambda expressions
/// <summary>
/// Fetches the photo stream data for a specified user.
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="continuationToken">Last captured ticks in the form of a string.</param>
/// <returns>List of photos up to the page size.</returns>
public async Task<PagedResponse<PhotoContract>> GetUserPhotoStream(string userId, string continuationToken)
{
var feedOptions = new FeedOptions
{
MaxItemCount = PhotoStreamPageSize,
RequestContinuation = continuationToken
};
var query = _documentClient.CreateDocumentQuery<PhotoDocument>(DocumentCollectionUri,
feedOptions)
.Where(d => d.DocumentType == PhotoDocument.DocumentTypeIdentifier)
.Where(d => d.DocumentVersion == _currentDocumentVersion)
.Where(p => p.UserId == userId)
.OrderByDescending(p => p.CreatedDateTime.Epoch)
.AsDocumentQuery();
var documentResponse = await query.ExecuteNextAsync<PhotoDocument>();
var photoContracts = await CreatePhotoContractsAndLoadUserData(documentResponse.ToList());
var result = new PagedResponse<PhotoContract>
{
Items = photoContracts,
ContinuationToken = documentResponse.ResponseContinuation
};
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment