According to your description, it seems that you need to add the [EnableQuery] attribute to the controller method for the stored procedure.
The following implementation works for me:
In WebApiConfig.cs :
builder.EntityType<Product>().Function("SomeFunction").ReturnsFromEntitySet<Product>("Products");
In ProductsController.cs :
[HttpGet] [EnableQuery] public IHttpActionResult SomeFunction() { return Ok(products.FirstOrDefault(c => c.ID == 1)); }
In browser:
GET http://localhost:54017/Products(1)/Default.SomeFunction()?$expand=Categories
gives
{ @odata.context: "http://localhost:54017/$metadata#Products", value: [ { ID: 1, Name: "Some", Categories: [ { ID: 1, Name: "Some" } ] } ] }
Updated 10.22.2014:
I changed the attached code and attached it below. Will you try if this works?
[HttpPost] [EnableQuery(PageSize=10)] public IHttpActionResult SomeFunction() { var results = db.SomeStoredProc().ToList(); return Ok(results); }
A similar feature worked in my tests. The reason for this is because the OData Web API automatically handles $skip , $top and paging. You do not need to worry about applying them to your result. The request parameters from the client will be applied to the entire set returned by you.
source share