Search code examples
.netasp.net-web-apiodataaggregation

OData v4.0 aggregate queries (aggregate query syntax)


For example, I have an object model:

Product
{ 
  int ProductId,
  string Name,
  List<Sale> Sales
}
  • I want to use the aggregate queries to get total Amount of Sales:

GET: Product?$apply=groupby(Name, aggregate(Sales(Amount with sum as Total))) (follow as oasis-open standard)

--> Got error: UriQueryExpressionParser_CloseParenOrCommaExpected=" ')' or ',' expected at position {0} in '{1}'. ". position at Amount.

  • I change the query to:

GET: Product?$apply=groupby(Name, aggregate(Sales/Amount with sum as Total))

--> Work successfully!.

My question:

--> Had current version OData Core supported the aggregate query syntax as my example "aggregate(Sales(Amount with sum as Total))" or NOT?

Please give me your advice.

Thank you very much


Solution

  • This is tracked at https://github.com/OData/odata.net/issues/463

    The query

    Product?$apply=groupby(Name, aggregate(Sales/Amount with sum as Total))
    

    should throw exception as well, it's not supported yet.