I have the following classes:
public class Product {
int Id;
string Slug;
ICollection<Price> Prices;
}
public class Price {
int Id;
float Amount;
PriceType Type;
}
public class PriceType {
int Id;
string Name;
bool isPublic;
}
I have an OData API that returns a list of products.
I want to get products ordered by the value "amount" of "Prices" using only a specific PriceType (name="final"), so the collection "Prices" comes always with one child.
For example the response could be:
[
{
Id: 1,
Slug: "432433",
Prices: [{Id:1, Amount: 1000, type:"final"}]
},
{
Id: 2,
Slug: "542131",
Prices: [{Id:1, Amount: 800, type:"final"}]
}
]
The problem is that I'm not able to use the $orderby clause in the OData query because the attribute Price comes as an array.
Below an example query used to get products:
http://{URL_API}/products/?
skip=0&
top=12&
expand=prices(filter=(PriceType/Name eq 'final'))&
select=id,slug,prices&
orderby=prices
which returns:
"error":
{
"code": "",
"message": "The query specified in the URI is not valid. The $orderby expression must evaluate to a single value of primitive type.",
}
Is there a way to sort results somehow? Thanks.