2016-09-05 1 views
4

왜 CreateDocumentQuery의 비동기 버전이 없습니까?DocumentClient CreateDocumentQuery async

예를 들어이 방법은 비동기하고하는의 수 :

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; 
    } 
+1

'CreateDocumentQuery'는 단순히 쿼리를 생성하고 실행하지 않는다고 생각합니다. 아마도 ToList 대신에 ToListAsync를 사용하여 비동기 적으로 쿼리를 실행할 수 있습니다. –

답변

8

좋은 질의,

그냥 비동기 방식으로 그것을 가지고 코드를 아래에보십시오.

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 
    } 
} 


}