[英]An exception about “Partition Routing Information” in reading a document from DocumentDB
您見過此異常消息嗎?
在32位進程中運行時,無法從查詢中提取分區路由信息。 為了完成查詢並避免出現此異常,請確保您的主機進程是64位的。 對於可執行應用程序,可以通過在“構建”選項卡上的項目屬性窗口中取消選中“首選32位”選項來完成。 對於基於VSTest的測試項目,可以通過從Visual Studio“測試”菜單選項中選擇“測試”->“測試設置”->“默認處理器體系結構為X64”來完成。 對於本地部署的ASP.NET Web應用程序,可以通過在“工具”->“選項”->“項目和解決方案”->“ Web項目”下選中“使用IIS Express的64位版本用於網站和項目”來完成。
當我想從DocumentDB中讀取文檔時,會收到此異常消息。 C#中用於檢索文檔的代碼如下(未檢查FeedOption):
FeedOptions queryOptions = new FeedOptions { EnableCrossPartitionQuery = true };
var conv = db.Client.CreateDocumentQuery<Model.Conversation>(
UriFactory.CreateDocumentCollectionUri(db.DatabaseName, db.CollectionName), queryOptions)
.Where(f => f.Id == "conversationId");
// the exception happens here
foreach(Conversation f in conv)
{
Debug.Print(f.Name);
}
在上面, db
是一個存儲庫,我可以確定Client
已正確啟動,因為我可以同時將文檔插入DocumentDB。
另外,您可以看到“對話”模型:
public class Conversation
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
public string Name { get; set; }
[JsonProperty("cid")]
public string CID { get; set; } // defined as a partition key
}
我應該提到在DocumentDB中有一個Id == "conversationId"
文檔,以下代碼在這種情況下可以正常工作,但這不是解決方案,因為我也想查詢Name
屬性,而不僅僅是查詢Id
:
Document doc = await db.Client.ReadDocumentAsync(
UriFactory.CreateDocumentUri(db.DatabaseName, db.CollectionName, "conversationId"),
new RequestOptions { PartitionKey = new PartitionKey("partitionKey") });
Conversation conv = (Conversation)(dynamic)doc;
我找到了解決方案。 在問題中,從1.11版的Microsoft.Azure.Document庫使用。 正如我在此鏈接中發現的那樣, CreateDocumentQuery
已過時,並且顯然api已更改。 因此,當我降級到1.10版時,一切正常。 因此,我對此感到非常高興!
結果, CreateDocumentQuery
在1.11版中已過時,您應該為每個集合定義一個partitionKey,其結果是您不能再使用CreateDocumentQuery
,除非您降級到1.10版或更低版本。 另外,我認為這是此版本中的錯誤,應予以報告。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.