Support for CountAsync()
See original GitHub issueIs your feature request related to a problem? Please describe.
In version 2.x of the SDK, we were able to execute asynchronous calls for determining the count of a IQueryable
. It seems like you can only perform this in a synchronous fashion in the current version of the SDK.
Describe the solution you’d like
Support the CountAsync()
LINQ syntax
Describe alternatives you’ve considered None, there doesn’t appear to be support for this currently.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
QueryableExtensions.CountAsync Method (System.Data. ...
Asynchronously returns the number of elements in a sequence.
Read more >CA1828: Do not use CountAsync/LongCountAsync when ...
This rule flags the CountAsync and LongCountAsync LINQ method calls used to check if the collection has at least one element.
Read more >c# - CountAsync() does not work even if the query returns ...
Before counting i had to make the query a list using .ToList() and now pagination works as expected! Thanks @simplygood for providing help....
Read more >Use Microsoft.Playwright.Core.Locator.CountAsync in ...
Use the CountAsync method in Microsoft.Playwright.Core package in your next Playwright-dotnet project with LambdaTest Automation Testing Advisor.
Read more >Asynchronous Querying
Marten adds extension methods to IQueryable for the asynchronous invocation of the common Linq operators: AnyAsync(); CountAsync(); MinAsync(); MaxAsync() ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@j82w Thanks for the response. We had a quick test with your above suggestion and had some interesting observations to share.
Test Scenarios:
DocumentClient
with synchronousCount
callDocumentClient
with asynchronousCountAsync
callCosmosClient
with sychronousCount
callCosmosClient
with above mentioned asychronous iterator async pattern Microsoft.Azure.DocumentDB.Core 2.5.1 Microsoft.Azure.Cosmos 3.0.0Test Code
Results
Observations
DocumentClient.CountAsync()
seems to be slower than the sync versionCount
on CosmosClient seems to be the faster of all so far!!We ran in to this issue as we are attempting to port our current 2.x SDK code to the new 3.x SDK. From this perspective, we have a large number of cases where we wish to perform various counts to a number of collections and we will often firing these off using
CountAsync
and simply execute aawait Task.WhenAll(tasks)
call to wait for them to all return.If it was possible, we’d love to see your proposal of
CountAsync
extension method, as we believe this is the most idiomatic syntax given where previous developers are migrating from. If the SDK could combine the performance of the current implementation ofCount
in an asynchronous manner, we would be very happy campers 😃With the newly released 3.1 SDK I’m now able to work around this issue with the following code.