How to get the sum of child entries using web api odata?

How can I return the total cost of OrderItems (ItemTotalPrice) in odata web api?

The web api odata doesn't seem to support $ apply, as described here: http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/cs01/odata-data-aggregation-ext -v4.0-cs01.html # _Aggregation_Methods_1

I have a odata web api request like:

http://localhost:29446/odata/OrderItems

which returns the following json:

{
  "odata.metadata": "http://localhost:29446/odata/$metadata#OrderItems",
  "value": [{
    "OrderItemID": 17,
    "ItemDescription": "test",
    "ItemQty": 1,
    "ItemUnitPrice": "1.10",
    "ItemTaxGroup": 1,
    "ItemTotalTax": "0.10",
    "ItemTotalPrice": "1.22",
    "ItemSubProgram": 1,
    "ItemAccount": 1,
    "ItemActualCost": "1.22",
    "OrderID": 3
  }, {
    "OrderItemID": 18,
    "ItemDescription": "test",
    "ItemQty": 1,
    "ItemUnitPrice": "1.10",
    "ItemTaxGroup": 1,
    "ItemTotalTax": "0.10",
    "ItemTotalPrice": "1.10",
    "ItemSubProgram": 1,
    "ItemAccount": 1,
    "ItemActualCost": "1.00",
    "OrderID": 3
  }, {
    "OrderItemID": 19,
    "ItemDescription": "test",
    "ItemQty": 1,
    "ItemUnitPrice": "1.10",
    "ItemTaxGroup": 1,
    "ItemTotalTax": "0.10",
    "ItemTotalPrice": "1.10",
    "ItemSubProgram": 1,
    "ItemAccount": 1,
    "ItemActualCost": "1.00",
    "OrderID": 3
  }, {
    "OrderItemID": 20,
    "ItemDescription": "test",
    "ItemQty": 1,
    "ItemUnitPrice": "1.10",
    "ItemTaxGroup": 1,
    "ItemTotalTax": "0.10",
    "ItemTotalPrice": "1.10",
    "ItemSubProgram": 1,
    "ItemAccount": 1,
    "ItemActualCost": "1.00",
    "OrderID": 3
  }, {
    "OrderItemID": 21,
    "ItemDescription": "test",
    "ItemQty": 1,
    "ItemUnitPrice": "1.10",
    "ItemTaxGroup": 1,
    "ItemTotalTax": "0.10",
    "ItemTotalPrice": "1.10",
    "ItemSubProgram": 1,
    "ItemAccount": 1,
    "ItemActualCost": "1.00",
    "OrderID": 3
  }]
}

I thought the below might work:

http://localhost:29446/odata/OrderItems?$apply=aggregate(ItemTotalPrice with sum as Total)

but I get the following error:

The query parameter '$apply' is not supported.

I am using OData v4 with Web API 2.2

+4
source share
2 answers

Web API 2.2 OData v4. pull ODataLib, Github .NET OData: https://github.com/OData/odata.net/pull/6, .

+1

, WebAPI-, .QueryByCube LINQ (www.adaptivelinq.com).

: AdaptiveLINQ.

0

All Articles