Query expression is invalid cosmosdb

∥☆過路亽.° 提交于 2020-01-16 08:40:18

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/48676519/query-expression-is-invalid-cosmosdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!