user7426734
user7426734

Reputation:

Query expression is invalid cosmosdb

I am trying to query using groupby in cosmosdb with the following query,

var result = client.CreateDocumentQuery<Login>(documentUri)
                  .Where(i => i.logevent == "Success" && i._ts > 1517405472 && i._ts <= 1518010272)
                  .GroupBy(t => t._ts);

it throws the following error

DocumentQueryException: Query expression is invalid, expression https://documents.azure.com/dbs/colls/test.Where(i => (((i.logevent == "Success") AndAlso (i._ts > 1517405472)) AndAlso (i._ts <= 1518010272))).GroupBy(t => t._ts) is unsupported. Supported expressions are 'Queryable.Where', 'Queryable.Select' & 'Queryable.SelectMany

Upvotes: 0

Views: 1225

Answers (1)

Aravind Krishna R.
Aravind Krishna R.

Reputation: 8003

GroupBy is not currently supported by the Cosmos DB LINQ provider. You have to materialize the results of the where clause using AsEnumerable, then perform Group By using LINQ on objects.

var result = client.CreateDocumentQuery<Login>(documentUri)
         .Where(i => i.logevent == "Success" && i._ts > 1517405472 && i._ts <= 1518010272)
         .AsEnumerable()
         .GroupBy(t => t._ts);

Note: you should push down as much of the query predicates to the server as possible. In other words, the Where clause should be in front of the AsEnumerable.

Upvotes: 3

Related Questions