0

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'.

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

2 Comments

I've tried both but they both threw and exception: COM.PixelPin.NoSQLService.Tests.AzureDocumentDbTests.TestQueryDocument threw exception: System.InvalidCastException: Unable to cast object of type 'Microsoft.Azure.Documents.Linq.DocumentQuery1[Microsoft.Azure.Documents.Document]' to type 'System.Linq.IQueryable1[COM.PixelPin.NoSQLService.Tests.Documents]'.
Just noticed that you have two different types for Document. Is that a typo? I edited my answer to match what should be from the service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.