是否可以使用DocumentDB .NET SDK对返回所有匹配文档的DB运行异步查询?
这个StackOverflow问题的答案是:使用DocumentDB查询Azure ExecuteNextAsync返回的值比MaxItemCount少表示:
在DocumentDB上执行查询的时间是有限制的。 ..。 如果达到这些限制,则可能返回部分结果集。
我知道,可以通过迭代分页结果来克服上述限制,如:(来源)
List<Family> families = new List<Family>();
FeedOptions options = new FeedOptions { MaxItemCount = 1 };
var query = client.CreateDocumentQuery<Family>(collectionLink, options).AsDocumentQuery();
while (query.HasMoreResults)
{
foreach (Family family in await query.ExecuteNextAsync())
{
families.Add(family);
}
}我的问题是-这个循环有必要吗?是否有一种更优雅的方法让SDK返回所有可用的结果(不分页)?
发布于 2016-08-01 23:05:23
您拥有的循环是对多个请求执行枚举的最佳方法,因为DocumentDB中的每个请求都有有限度的时间执行。
您可以将此代码包装在扩展方法中,以方便使用。
这是DocumentDB团队添加这种支持- https://github.com/Azure/azure-documentdb-dotnet/issues的一个很好的建议。
https://stackoverflow.com/questions/38570663
复制相似问题