【问题标题】:OData aggregate query with Count使用 Count 的 OData 聚合查询
【发布时间】:2017-01-02 13:18:56
【问题描述】:

在 odata 5.3.1 中,聚合查询不起作用,因此我编写了自定义 facet 类来获取项目的聚合计数。 http://localhost/odata/Document$apply=groupby((Category),%20aggregate(Document/$count%20as%20Total))

但在 Odata 5.9.1 中,上述查询失败,因为它已经包含聚合函数。所以对于我的自定义方法,它不起作用。

GithHub aggregate function

我想要这样的数据:

  "value": [
{ "name" : "doc1", "version" 2: , "total": 5 },
{ "name" : "doc2", "version" 1: , "total": 8 },
{ "name" : "doc2", "version" 2: , "total": 2 },

]

那么查询应该如何? 这里的“版本”是一个字符串属性。

【问题讨论】:

    标签: asp.net-web-api2 odata


    【解决方案1】:

    为该操作找到了正确的查询。将相同的类属性添加到您的模型类。让有一个名为 Document 的模型类并添加一个属性

    public Document Documents {get;set;} 
    

    那么对于 Asp.net Odata 5.9.1 使用关键字 countdistinct

     http://localhost/odata/Document?$apply=groupby((Category), aggregate(Documents with countdistinct as Total))
    

    所以它返回准确的总数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-27
      • 1970-01-01
      • 2021-08-23
      • 2019-05-24
      • 1970-01-01
      • 2015-05-12
      • 2010-12-17
      相关资源
      最近更新 更多