2016-04-27 14 views
0

我有以下查詢來檢查Azure DocumentDb數據庫是否存在。此代碼目前與SDK的功能一起使用nuget包版本1.62,但在1.63和1.7中引發運行時空對象異常。當檢查數據庫是否存在Microsoft.Azure.DocumentDb時,Object Null異常nuget包> 1.62

這是錯誤的方式來查詢數據庫是否存在或在以後的SDK版本中是否存在問題?

感謝

using (IReliableReadWriteDocumentClient dbClient = GetDocumentClient()) 
{ 
    // Check to verify a database with the id does not exist 
    Database database = dbClient.CreateDatabaseQuery().Where(db => db.Id == databaseId).AsEnumerable().FirstOrDefault(); 

    // If the database does not exist, create a new database 
    if (database == null) 
    { 
     ... 
    } 
} 

回答

0

你的意思是代碼可以在1.6.2運行,但拋出1.6.3或1.7一個空對象異常?

我看不到你的代碼在IReliableReadWriteDocumentClient dbClient = GetDocumentClient()後面,但是我在1.6.2或1.6.3中成功運行了下面的代碼。

DocumentClient client= new DocumentClient(new Uri(EndpointUri), PrimaryKey); 
    var databaseName = "lilidatabasedb"; 
    Database database = client.CreateDatabaseQuery().Where(db => db.Id == databaseName).AsEnumerable().FirstOrDefault(); 

仔細檢查你的代碼,你可以在這裏粘貼更多代碼來獲得更多幫助。

相關問題