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