0
我想查詢從documentDB我的文件之一,但它似乎沒有奏效,這是我如何設置它:文檔DB查詢
NoSQLService:
private INoSQLProvider client;
private static IContainer container;
public NoSQLService(INoSQLProvider provider)
{
client = provider;
}
public static dynamic QueryDocument<T>(Uri reference, FeedOptions queryOptions)
{
var documentDB = container.Resolve<INoSQLProvider>();
return documentDB.QueryDocumentAsync(reference, queryOptions);
}
INoSQLProvider:
IOrderedQueryable<Document> QueryDocumentAsync(Uri reference, FeedOptions queryOptions);
AzureDocumentDBService從INoSQLProvider
private readonly IDocumentClient client;
public IOrderedQueryable<Document> QueryDocumentAsync (Uri reference, FeedOptions queryOptions)
{
return client.CreateDocumentQuery(reference, queryOptions);
}
AzureDocumentDBService
繼承AzureDocumentDBTest
FeedOptions queryOptions = new FeedOptions();
Documents document = new Documents();
document.id = "112";
queryOptions.MaxItemCount = -1;
var reference = NoSQLService.CreateDocumentUri("ppsession1", "callumtest");
IQueryable<Documents> documentQuery = NoSQLService.QueryDocument<Documents>(reference, queryOptions).Where(document.id = "112");
foreach (Documents documents in documentQuery)
{
Console.WriteLine("\tRead {0}", documents);
}
當我運行測試我得到一個異常:
微軟,CSparp.RuntimeBuilder.RuntimeBinderException: '物體'd oes 不包含'Where'的定義。
我都試過,但他們都拋出和異常:COM.PixelPin.NoSQLService .Tests.AzureDocumentDbTests.TestQueryDocument引發異常: System.InvalidCastException:無法將類型爲'Microsoft.Azure.Documents.Linq.DocumentQuery'1 [Microsoft.Azure.Documents.Document]'的類型的對象轉換爲鍵入'System.Linq.IQueryable '1 [COM.PixelPin.NoSQLService.Te sts.Documents]」。 – Callum
剛注意到''Document'有兩種不同的類型。這是一個錯字嗎?我編輯了我的答案,以匹配應該從服務 – Nkosi
工作,這一次是一個錯字。 – Callum