2017-01-02 77 views
0

在odata 5.3.1聚合查詢不起作用,因此我編寫了自定義構面類以獲取項目的聚合計數。 http://localhost/odata/Document $應用= GROUPBY((類別),%20aggregate(文檔/ $計數%20AS%20Total))使用計數的OData聚合查詢

但在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 }, 

]

那麼如何查詢應該是什麼? 這裏的「版本」是一個字符串屬性。

回答

0

找到適合此操作的正確查詢。將相同的類屬性添加到您的模型類。我們有一個名爲文檔&模型類添加屬性

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)) 

所以它返回準確的總計數。