c# - Document DB query -
i'm trying query 1 of documents documentdb doesn't appear working, how set 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 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 run test exception:
microsoft,csparp.runtimebuilder.runtimebinderexception: 'object' not contain definition 'where'.
you returning dynamic
nosqlservice.querydocument
, trying apply linq extension method where
on it. cannot do. have cast can work extension.
so either change nosqlservice
using dynamic
public static iqueryable<document> querydocument<t>(uri reference, feedoptions queryoptions) { var documentdb = container.resolve<inosqlprovider>(); return documentdb.querydocumentasync(reference, queryoptions); }
or cast result in test
var reference = nosqlservice.createdocumenturi("ppsession1", "callumtest"); iqueryable<document> documentquery = ((iqueryable<document>)nosqlservice.querydocument<document>(reference, queryoptions)).where(document => document.id == "112");
Comments
Post a Comment