From some thirdparty we use the backend which been updated from OData v3 to v4. That means we have to update our software as well.
Now the problem i'm facing is that the way collections work are different in v4 than they where in v3. For example, the code i used to GET ~/OData/Orders
and also the OrderItems
and in the OrderItems
collection expand the object Product was:
SomeDataServiceContext.Orders.Expand("OrderItems").Expand("OrderItems/Product").Take(10)
Now with OData v4 i can expand the OrderItems
, but the expand of the Product object within the OrderItems
collection don't work anymore. This is the code i now use:
SomeDataServiceContext.Orders.Expand(Function(x) x.OrderItems).Take(10)
But as you can see this does retrieve the collection of OrderItems
but don't expand the Product object within the OrderItems
collection. The OrderItems
Collection however does contain the property ProductId
So in this case what would be the right approach:
SomeDataServiceContext.Products
to get the corresponding productMy knowledge about OData is beginner to medium level, so be gentle ;-)
From the client there is lambda syntax support for nested expansions only if the link is singluar, as Order.OrderItems
is a collection you can use the string variant of the expand method:
SomeDataServiceContext.Orders.Expand("OrderItems($expand=Product)").Take(10)
You will notice here, expansion syntax is one of the breaking changes in URL parsing between OData v3 and v4.