I have a API controller with the following method used to retrieve one specific object. The output is formatted in Json.
[Route("~/api/orders({key:int})", Name = "GetOrder")]
public IHttpActionResult GetOrder([FromODataUri] int key, ODataQueryOptions<Order> queryOptions)
It works as follows.
- Build up a base query from Entity Framework named baseQuery
Apply the Odata filters to the base query using
queryOptions.ApplyTo(baseQuery.OrderByDescending(f => f.Id) , querySettings);
Return the resulting IQueryable
The problem is that this results in a list containing one object (the one asked for). I would like to have it return the object itself rather then a list with the object.
I have tried adding FirstOrDefault() to the baseQuery but that causes the query to be executed and the OData filter cannot be applied after that.