【问题标题】:Query expression is invalid cosmosdb查询表达式无效 cosmosdb
【发布时间】:2018-02-08 02:27:53
【问题描述】:

我正在尝试通过以下查询在 cosmosdb 中使用 groupby 进行查询,

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

它会抛出以下错误

DocumentQueryException:查询表达式无效,表达式 https://documents.azure.com/dbs/colls/test.Where(i => (((i.logevent == “成功”) AndAlso (i._ts > 1517405472)) AndAlso (i._ts t._ts) 不受支持。支持的 表达式是 'Queryable.Where', 'Queryable.Select' & 'Queryable.SelectMany

【问题讨论】:

  • 您可以尝试关注由 Larry Maccherone 撰写的 documentdb-lumenize,以在 DocumentDB 中提供聚合(分组、数据透视表和 N 维立方体)和时间序列转换作为存储过程。跨度>

标签: c# azure azure-cosmosdb


【解决方案1】:

Cosmos DB LINQ 提供程序当前不支持 GroupBy。您必须使用 AsEnumerable 实现 where 子句的结果,然后对对象使用 LINQ 执行 Group By。

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

注意:您应该尽可能多地将查询谓词下推到服务器。也就是说,Where 子句应该在 AsEnumerable 之前。

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-05
  • 1970-01-01
相关资源
最近更新 更多