22

http://services.odata.org/V4/Northwind/Northwind.svc/

I'm trying to get all Customers, their Orders and corresponding Order_Details at once and using nested $expand for that. To query the data I'm using following link: http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$expand=Orders($expand=Order_Details)

Now I'm trying to limit the data using $select. The problem is that I can not find the proper syntax to use $select for the middle table - Orders. I can apply it just to the top table - Customers and to the bottom one - Order_Details like this:

http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$select=CustomerID&$expand=Orders($expand=Order_Details($select=UnitPrice))

Is it possible to use $select also for tables in between, in my case for Orders?

VladL
  • 12,769
  • 10
  • 63
  • 83
  • Did you really need to get these data as nested objects ? From experience I have found that in most cases, **we need an aggregated view of an object tree**. I developed the LINQ extension method `QueryByCube` to build this kind of service queryable using the OData protocol. Read more here: [AdaptiveLINQ](http://www.adaptivelinq.com). – nlips May 18 '15 at 21:45
  • @nlips I can't use LINQ, we are still limited to .NET 2.0. Could you please give me an example of an aggregated view? Basicly I'm trying to get all those data with as few web requests as possible – VladL May 18 '15 at 21:52
  • I assumed that the use of Northwind.svc is for example. I guess you will develop your own OData services and use LINQ server-side. The idea of an aggegated view is to present an entity set where each field is built by an expression in the native entity model. **Some fields are expressed as an aggregation of several items**. For example, we can obtain the _total sales per customer by date_ by simply making the request : `MyService.svc?$select=CustomerID,OrderDate,TotalSales`. – nlips May 18 '15 at 22:27
  • @nlips I'm writing a data provider that will use existing OData services so I have to implement the "worst case" :) – VladL May 19 '15 at 06:00

1 Answers1

26

Thanks @nlips for his comment.

It is possible to use $select for the middle table by just separating select and expand with semicolon:

http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$select=CustomerID&$expand=Orders($select=OrderID;$expand=Order_Details($select=UnitPrice))

Community
  • 1
  • 1
VladL
  • 12,769
  • 10
  • 63
  • 83
  • 7
    Holy guacamole a semicolon... Wasted hours on this. Care to share some source doc? – Jerther Dec 15 '15 at 20:47
  • 1
    @Jerther as you see, I've answered my own question. I've also wasted hours on this and came to the solution just by accident. Not sure about now, but at the moment of writing I couldn't find this in official docs. – VladL Dec 16 '15 at 07:58
  • 4
    There is mention of it, but no example. The word semicolon appears only once in the whole document: http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html – Jerther Dec 16 '15 at 15:19