Reputation: 23
I have a complex document, which I simplified below:
{
Name: "Foo",
Characteristics: [
{ Label: "Brand", Values: ["TheBrand"] },
{ Label: "Category", Values: ["TheCategory"] },
{ Label: "Colors", Values: ["blue", "red"] }
]}
As you can see, the values inside the nested 'Characteristics' array are also specified within an array.
I need to be able to order these documents by Name, but also by Brand, or by Category. Ordering by Name is simple enough. But the nested arrays are tricky to deal with.
All my attempts to order by Brand or Category failed, generating various exceptions.
I can't do a First() nor a FirstOrDefault() => DocumentQueryException: Method 'First' is not supported.
I tried to do a Select such as the one below, but I ended up with the Exception "ORDER BY item expression could not be mapped to a document path."
var query = client.CreateDocumentQuery<T>(documentCollectionUri)
.Select(d => new
{
Document = d,
Brand = d.Values.Where(v => v.Label == "Brand").Select(v => v.Values)
});
query = query.OrderBy(q => q.Brand); // Exception!
Any ideas? Thanks in advance!!
*** EDIT *** It's been a long time, but I notice I have thanked you @Richard, so I wanted to fix my mistake! Thank you! We indeed gave up on using linq and queried the cosmos db manually using Microsoft.Azure.Cosmos.QueryDefinition and Cotnainer.GetItemQueryIterator()
Upvotes: 0
Views: 90
Reputation: 109130
Given indexing into collections is not supported yet (see this issue I your case of using value from search in collection to use later is a long way from supported.
The CosmosDB EF support is very limited compared to RDBMS support: you may be better off just querying using the Cosmos DB API directly (and in the SQL SDK this wouldn't be easy to do).
Upvotes: 0