Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Created June 23, 2020 11:53
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 gsscoder/9c6f724a4acd7ee1b4f93f19330df1bd to your computer and use it in GitHub Desktop.
Save gsscoder/9c6f724a4acd7ee1b4f93f19330df1bd to your computer and use it in GitHub Desktop.
C# extension method to copy all CosmosDB iterator items to a sequence
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
public static class FeedIteratorExtensions
{
public static async Task<IEnumerable<T>> ReadAllAsync<T>(this FeedIterator<T> iterator)
{
var result = new List<T>();
while (iterator.HasMoreResults) {
result.AddRange(await iterator.ReadNextAsync());
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment