I'm trying to write Read method where maxItemCount continuation token is passed as arguments, but I'm not able to find any updated guides on how to implement it. The code I have now looks like this, but I can't believe there's no easier way to implement this basic functionality?
public async Task<(IEnumerable<T> Results, string ContinuationToken)> ReadAsync(Expression<Func<T, bool>> predicate, int limit, string continuationToken)
{
var entityList = new List<T>();
int itemsRemaining = limit;
do
{
var maxItemsCount = Math.Min(itemsRemaining, 100);
var options = new QueryRequestOptions { MaxItemCount = maxItemsCount };
var query = _container.GetItemLinqQueryable<T>(true, continuationToken, options).Where(predicate);
using (var iterator = query.ToFeedIterator())
{
if (iterator.HasMoreResults)
{
FeedResponse<T> response = await iterator.ReadNextAsync();
entityList.AddRange(response.Resource);
continuationToken = response.ContinuationToken;
if (iterator.ReadNextAsync().Result.Count == 0)
continuationToken = null;
}
}
itemsRemaining -= maxItemsCount;
}
while (itemsRemaining > 0);
return (entityList, continuationToken);
}