问题
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
andCustomerName
- 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