Todd Thompson
Todd Thompson

Reputation: 21

Using the cosmosdb linq provider, can you chain a where clause outside a nested SelectMany?

I'm try to write a linq document query query that looks like the following:

var query = _documentClient.CreateDocumentQuery<T>(uri, feedOptions)
            .SelectMany(queryExpression).Where(expression)
            .AsDocumentQuery();

Where the .Where(expression) filters on the parent of the join (the customer reference below) and not that array element (orders). The .SelectMany(queryExpression) looks something like this:

customer => customer.Orders
            .Where(c => c.OrderId == orderId) &&
                        c.ORderType == OrderType.Customer)
            .Select(d => customer);

When I look at the actual query string, it looks something like this:

SELECT VALUE root FROM root JOIN c IN root["Orders"] WHERE (((c["OrderId"] = "635debcf-d77f-430e-90f2-ca51afc6b685") AND (c["OrderType"] = 0)) AND ( c["Age"] > 35) 

What I want is something that looks like:

SELECT VALUE root FROM root JOIN c IN root["Orders"] WHERE (((c["OrderId"] = "635debcf-d77f-430e-90f2-ca51afc6b685") AND (c["OrderType"] = 0)) AND ( root["Age"] > 35) 

So my question is: Is there a way, using the linq provider, to chain a WHERE outside the nestest SELECTMANY statement that filters against parent document - root in this case?

Upvotes: 1

Views: 583

Answers (1)

Todd Thompson
Todd Thompson

Reputation: 21

The answer is that Microsoft's client is broken: https://github.com/Azure/azure-documentdb-dotnet/issues/208

Upvotes: 1

Related Questions