/// <summary> /// Creates a pagination wrapper with Continuation Token support /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <returns></returns> public static async Task <PagedResults <T> > ToPagedResults <T>(this IOrderedQueryable <T> source) { var documentQuery = source.AsDocumentQuery(); var results = new PagedResults <T>(); try { var queryResult = await documentQuery.ExecuteNextAsync <T>(); if (!queryResult.Any()) { return(results); } results.ContinuationToken = queryResult.ResponseContinuation; results.Results.AddRange(queryResult); } catch { //documentQuery.ExecuteNextAsync throws an Exception if there are no results return(results); } return(results); }
public static async Task <T> GetFirstOrDefault <T>(this IOrderedQueryable <T> queryAll) { return((await queryAll.AsDocumentQuery().GetAllResultsAsync()).FirstOrDefault()); }