2016-08-12 111 views
0

我遷移C#網頁API使用; 2,蒙戈驅動程序版本2,這裏的我試過的代碼,但我有一個問題,使用DocumentsAffected沒有擴展方法DeleteOneAsync和writeConcernResult.DocumentsAffected沒有擴展方法

public Task<bool> RemoveRefreshToken(string refreshTokenId) 
     { 

      var query = Builders<RefreshToken>.Filter.Where(r => r.Id==refreshTokenId); 
      var writeConcernResult = mongoContext.RefreshTokens.DeleteOneAsync(query); 
      return Task.FromResult(writeConcernResult.DocumentsAffected == 1); 
     } 

你知道我在這裏失蹤了嗎?

感謝

回答

1

您可以從DeleteOneAsync()使用Task<DeleteResult>類型的返回值的DeletedCount財產。在您的方法頭中也使用async以利用異步方法:

async Task<bool> RemoveRefreshToken(string refreshTokenId) 
{ 
    var query = Builders<RefreshToken>.Filter.Where(r => r.Id==refreshTokenId); 
    var writeConcernResult = await mongoContext.RefreshTokens.DeleteOneAsync(query); 
    return Task.FromResult(writeConcernResult.DeletedCount == 1); 
}