How to use paging specifically for a list that is part of JSON using the OData asp.net protocol

The following is the get method in my controller. It returns a JSON containing the logical "success", the string "message" and a list. How can I query a list using OData? In general, if the return type was IQueryable, then will api / Category / all work? $ Top = 5 get the top 5 ... But what should I do in my case?

// Get all Categories
    [HttpGet]
    [ActionName("all")]
    [Queryable]
    public HttpResponseMessage GetCategoryList()
    {          

        var categoryList = this.Repository.GetCategories().AsQueryable<Category>();

        return Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage<IQueryable<Category>> { success = true, data = categoryList });

    }

public class ResponseMessage<T>  where T: class
{
    public string message;

    public bool success;

    public T data;
}
+1
source share
2 answers

, , , , odata​​strong > . , ODATA, , , . , .

, Microsoft ASP.NET Web API OData 0.2.0-alpha, , -.

, , . , GetCategoryList(int top), . X.

+1

ODataQueryOptions<T> . :

[HttpGet]
[ActionName("all")]
public HttpResponseMessage GetCategoryList(ODataQueryOptions<Category> options)
{          

    var categoryList = this.Repository.GetCategories().AsQueryable<Category>();
    categoryList = options.ApplyTo(categoryList) as IQueryable<Category>;

    return Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage<IQueryable<Category>> { success = true, data = categoryList });

}

ODataQueryOptions , QueryableAttribute.

+1

All Articles