Last active
March 15, 2016 06:51
-
-
Save EricAtMSFT/221b1cabbe3178be07f5 to your computer and use it in GitHub Desktop.
DocumentDB query using simple lambda expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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