Reputation: 149
I'm trying to query one of my documents from documentDB but it doesn't appear to be working, this is how i set it up:
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
AzureDocumentDBService
inherits from INoSQLProvider
private readonly IDocumentClient client;
public IOrderedQueryable<Document> QueryDocumentAsync (Uri reference, FeedOptions queryOptions)
{
return client.CreateDocumentQuery(reference, queryOptions);
}
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);
}
When I run the test I get an exception:
Microsoft,CSparp.RuntimeBuilder.RuntimeBinderException: 'object' does not contain a definition for 'Where'.
Upvotes: 0
Views: 1754
Reputation: 247123
You are returning dynamic
from NoSQLService.QueryDocument
and then trying to apply Linq extension method Where
on it. Which you cannot do. You would have to cast it to something that can work with that extension.
So either change your NoSQLService
from using the dynamic
public static IQueryable<Document> QueryDocument<T>(Uri reference, FeedOptions queryOptions)
{
var documentDB = container.Resolve<INoSQLProvider>();
return documentDB.QueryDocumentAsync(reference, queryOptions);
}
or cast the result in your test
var reference = NoSQLService.CreateDocumentUri("ppsession1", "callumtest");
IQueryable<Document> documentQuery = ((IQueryable<Document>)NoSQLService.QueryDocument<Document>(reference, queryOptions)).Where(document => document.id == "112");
Upvotes: 1