Does Asp.net Web API 2.2 OData4 support group by clause?

核能气质少年 提交于 2019-12-10 16:51:34

问题


Does Asp.net Web API 2.2 OData4 support aggregates and groupby clause? I could not find any conclusive answer to this .


回答1:


An alternative is to implement your service using the QueryByCube linq extension method provided by the AdaptiveLINQ component.

For example:

[EnableQuery]
public IQueryable<SalesCubeItem> Get()
{
     return DataContext.OrderDetails.QueryByCube(new SalesCubeDefinition());
}

where SalesCubeDefinition define:

  • 2 dimensions: ProductName and CustomerName
  • 2 measures: Sales, Quantity

you can query the sales per customer using the OData protocol like this:

http://.../salesAnalysis?$select=CustomerName,Sales

or quantity sold by product:

http://.../salesAnalysis?$select=ProductName,Quantity

and of course you can combine this with other OData operators ($filter, $orderby...)

Disclaimer: I'm the AdaptiveLINQ developer



来源:https://stackoverflow.com/questions/26020725/does-asp-net-web-api-2-2-odata4-support-group-by-clause

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