gpt4 book ai didi

c# - DocumentClient CreateDocumentQuery 异步

转载 作者:太空狗 更新时间:2023-10-29 17:32:29 25 4
gpt4 key购买 nike

为什么没有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com