I've Product
Entity in my OData EDM, with a GUID
key property, but I want to enforce results of the EntitySet to be sorted with another property Number
if $orderby
is not used. So I want to be able to use $orderby
normally, but in case it is absent, I want to add it inside the controller action to ODataQueryOptions
, here is what I reached to so far.
[EnableQuery()]
public IQueryable<Product> Get(ODataQueryOptions<Product> queryOptions)
{
if (queryOptions.OrderBy == null)
{
// do something to add $orderby=Number to queryOptions
}
return _ProductRepository.GetAll();
}
The problem here is that queryOptions.OrderBy
is read-only and I cannot assign to it.
Any Suggestions? Please.