Azure DocumentDB - Part 9 (使用 .NET SDK 查詢 DocumentDB)認識了 DocumentDB SQL 語法,也看過如何使用 LINQ to DocumentDB SQL 來查詢 DocumentDB 上的資料,接著我們來了解在 .NET 專案中要怎樣才能執行 DocumentDB 查詢
1.1 專案按右鍵 --> Manage NuGet Packages
1.2 Browse --> 搜尋 Microsoft.Azure.DocumentDB --> 安裝
Install-Package Microsoft.Azure.DocumentDB
Prefer 32-bitPrefer 32-bit 錯誤訊息
Partition routing information cannot be extracted from the query when running in a 32-bit process. To complete your query and avoid this exception, ensure that your host process is 64-bit.
For Executable applications, this can be done by unchecking the "Prefer 32-bit" option in the project properties window, on the Build tab. 
For VSTest based test projects, this can be done by selecting Test->Test Settings->Default Processor Architecture as X64, from Visual Studio Test menu option.
For locally deployed ASP.NET Web applications, this can be done by checking the "Use the 64 bit version of IIS Express for web sites and projects", under Tools->Options->Projects and Solutions->Web Projects.
using Microsoft.Azure.Documents.Client;
2-1.  DocumentDB endpointUrlprivate static readonly string endpointUrl = "endpointUrl";
2-2.  authorizationKey
private static readonly string authorizationKey = "authorizationKey";
唯讀金鑰,保障安全性
DocumentClientusing (DocumentClient client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
{
}
FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };//'-1' 使用動態數量.
collection link使用 databaseId 與 collectionId 建立 collection 的連結
5-1. databaseId
5-2. collectionId
5-3. 建立 collection linkUri collectionUri = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId);
DocumentDB 的查詢DocumentClient 、 collection link 及 FeedOptions 建立 IQueryable 物件dynamic 可以改為 .NET 物件var familyQuery = client.CreateDocumentQuery<dynamic>(collectionUri, queryOptions);
var testResult= familyQuery.ToList();
如果執行出現錯誤請檢查是否專案建置 未取消 Prefer 32-bit, 請參考上面的 取消專案預設使用 32-bit 相關設定
[JsonProperty(PropertyName = "json_property_name")] 來指定對應名稱