c# - DocumentClient CreateDocumentQuery 异步

标签 c# azure-cosmosdb

为什么没有 CreateDocumentQuery 的异步版本?

这个方法例如可以是异步的:

    using (var client = new DocumentClient(new Uri(endpointUrl), authorizationKey, _connectionPolicy))
    {
        List<Property> propertiesOfUser =
            client.CreateDocumentQuery<Property>(_collectionLink)
                .Where(p => p.OwnerId == userGuid)
                .ToList();

        return propertiesOfUser;
    }

最佳答案

很好的查询,

只需尝试以下代码以异步方式使用它。

DocumentQueryable.CreateDocumentQuery 方法为集合下的文档创建查询。

 // Query asychronously.
using (var client = new DocumentClient(new Uri(endpointUrl), authorizationKey, _connectionPolicy))
{
     var propertiesOfUser =
        client.CreateDocumentQuery<Property>(_collectionLink)
            .Where(p => p.OwnerId == userGuid)
            .AsDocumentQuery(); // Replaced with ToList()


while (propertiesOfUser.HasMoreResults) 
{
    foreach(Property p in await propertiesOfUser.ExecuteNextAsync<Property>())
     {
         // Iterate through Property to have List or any other operations
     }
}


}

关于c# - DocumentClient CreateDocumentQuery 异步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39338131/

相关文章:

azure - 在 CosmosDB 中创建表的正确方法是什么?

azure - 我可以在 Azure Cosmos DB 中的复合索引中为数组建立索引吗?

c# - 将 json null 发送到 Controller 会导致包含 0 个元素的列表

c# - 使用 TestHost 进行 Asp Net Core 测试,未找到 WebApplication TestFixture 类

c# - C# 面板和 UserControl 之间的区别

azure-cosmosdb - DocumentDb - 查询嵌套文档和根级别

azure - 如何在本地运行 Microsoft Azure DocumentDB?

c# - wpf 目标属性依赖

c# - 无论如何在 C# 中缓存函数/方法

c# - 如何排查从 Azure Function 向 Azure Cosmos 插入缓慢的问题