MiddleTommy
MiddleTommy

Reputation: 389

CosmosDb Linq Count v3 SDK

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

Answers (2)

MiddleTommy
MiddleTommy

Reputation: 389

version 3.2 of the SDK adds the Async Aggregates feature.

Upvotes: 2

Hury Shen
Hury Shen

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

Related Questions