我遇到了异步编程问题。 (类似于此ExecuteNextAsync freezes/hangs in Azure Cosmos DB)
它挂在网上:返回结果; 我试着说return results.ToArray();但没有运气
public async Task<IActionResult> Index()
{
var items = await DocumentDBRepository<Plane>.GetItemsAsync(d => d.Active);
return View(items);
}
public static async Task<IEnumerable<T>> GetItemsAsync(Expression<Func<T, bool>> predicate)
{
IDocumentQuery<T> query = client.CreateDocumentQuery<T>(
UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId))
.Where(predicate)
.AsDocumentQuery();
List<T> results = new List<T>();
while (query.HasMoreResults)
{
try
{
var result = await query.ExecuteNextAsync<T>();
results.AddRange(result);
}
catch (Exception e)
{
string s = e.Message;
}
}
// return results.ToArray();
return results.ToArray();
}