带计数的OData聚合查询 [英] OData aggregate query with Count

查看:288
本文介绍了带计数的OData聚合查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在odata 5.3.1中,聚合查询无法正常工作,因此我编写了自定义构面类以获取项目的聚合计数. http://localhost/odata/Document $ apply = groupby((Category),%20aggregate( Document/$ count%20as%20Total))

In odata 5.3.1 the aggregate query was not working so that I wrote my custom facet class to get aggregate count of items. http://localhost/odata/Document$apply=groupby((Category),%20aggregate(Document/$count%20as%20Total))

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

But in Odata 5.9.1 the above query is failing as because it has already aggregate function included. So for my custom method it is not working.

GithHub聚合函数

我想要这样的数据:

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

]

那么查询应该如何? 这里的版本"是字符串属性.

So how the query should be? Here "version" is a string property.

推荐答案

为该操作找到了正确的查询.将相同的类属性添加到您的模型类.让我们有一个称为Document&的模型类.添加属性

Found the right query for this operation. Add same class property to your model class. Let there is model class called Document & add a property

public Document Documents {get;set;} 

然后,对于Asp.net Odata 5.9.1,使用关键字 countdistinct

Then for Asp.net Odata 5.9.1 use key word countdistinct

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

因此它返回的是确切的总数.

So it's returning exact Total count.

这篇关于带计数的OData聚合查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆