I need to be able to convert from ODataQueryOptions to RestRequest in order to be able to issue a RestRequest with specified filters, and have created the following helper class:
public static class ODataQueryFilterToRestClient
{
public static RestRequest Map(ODataQueryOptions odataQuery)
{
var restRequest = new RestRequest();
if (odataQuery.Filter != null)
{
restRequest.AddQueryParameter(@"$filter", odataQuery.Filter.RawValue);
}
if (odataQuery.Top != null)
{
restRequest.AddQueryParameter(@"$top", odataQuery.Top.RawValue);
}
if (odataQuery.Skip != null)
{
restRequest.AddQueryParameter(@"$skip", odataQuery.Skip.RawValue);
}
if (odataQuery.OrderBy != null)
{
restRequest.AddQueryParameter(@"$orderby", odataQuery.OrderBy.RawValue);
}
//etc
return restRequest;
}
}
Given that OdataQueryOptions supports the following:
Is there a simpler way to make the conversion between ODataQueryOptions to RestClient, or another rest client proxy?
On a side note, I don't know if there's a better way to accept parameters through a controller than ODataQueryOptions?