Reputation: 389
Does anyone know how to (in the new v3 SDK for Azure CosmosDB) from a LINQ IQueryable asynchronously get a Count?
var con = col.Container();
IQueryable<T> q = con.GetItemLinqQueryable<T>(false);
q = q.Where(d => d._type == type);
int count = await q.CountAsync()///this is an SDK internal method and does not work
Upvotes: 1
Views: 518
Reputation: 15724
You can have a try with the code below(make some changes according to your actual situation):
var con = col.Container();
IQueryable<T> q = con.GetItemLinqQueryable<T>(false);
var iterator = q.Where(d => d._type == type).ToFeedIterator();
int totalCount = 0;
while (iterator.HasMoreResults)
{
var result = await iterator.ReadNextAsync();
totalCount += result.Count();
}
Upvotes: -1