1
votes

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
2
The feature is currently in development and due to be released in the near future - Nick Chapsas
Thanks for the reply. I have learned when CosmosDb says in the near future it could mean in the next 36 months (or longer if they find a new API they want to release 😁). - MiddleTommy

2 Answers

2
votes

version 3.2 of the SDK adds the Async Aggregates feature.

-1
votes

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();
}