当我只需要计数而无需阅读Document-Db数据库中的所有文档时,如何使用Linq构造IQueryable查询? [英] How to construct IQueryable query using Linq when I just need count without reading all documents in Document-Db database?
本文介绍了当我只需要计数而无需阅读Document-Db数据库中的所有文档时,如何使用Linq构造IQueryable查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Azure Cosmos Db数据库中的集合中存储的文档数.如何在IQueryable
对象上使用LINQ查询获得计数?
I need the number of documents stored in a collection in my Azure Cosmos Db database. How can I get the count using LINQ query on the IQueryable
object?
docDbClient.CreateDocumentQuery<TResult>().Count()
如果执行上述操作,我将无法通过.AsDocumentQuery()
方法进行跟踪.
If I do above, I am unable to follow it up with .AsDocumentQuery()
method.
推荐答案
这是我的异步实现(对于同步版本,请使用Count):
This is my async implementation (use Count, for the sync version):
var count = await DocumentClient.
CreateDocumentQuery<T>(CreateCollectionUri(), CreateFeedOptions()).
Where(predicate).
CountAsync();
谓词为Expression<Func<T, bool>>
这篇关于当我只需要计数而无需阅读Document-Db数据库中的所有文档时,如何使用Linq构造IQueryable查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文