2
votes

I was working through the following answer found here: Web API OData Inlinecount not working

Here is my controller, with some dummy data being served.

[Queryable]
public class ValuesController : ApiController
{
    // GET api/values
    public PageResult<Category> Get(ODataQueryOptions<Category> queryOptions)
    {
        var returnValue = new List<Category>()
        {
            new Category() { Id = 1, Name= "Category 1"},
            new Category() { Id = 2, Name= "Category 2"},
            new Category() { Id = 3, Name= "Category 3"},
        };

        IQueryable results = queryOptions.ApplyTo(returnValue.AsQueryable());

        return new PageResult<Category>(results as IEnumerable<Category>,
            Request.GetNextPageLink(), Request.GetInlineCount());
    }
}

I get the following error when I try to do a get via Fiddler:

"The action 'Get' on controller 'Values' with return type 'System.Web.Http.OData.PageResult`1[[ODataTest_Solution.DTO.Category, ODataTest Solution, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' cannot support querying. Ensure the type of the returned content is IEnumerable, IQueryable, or a generic form of either interface."

If I change the method it to return an IQueryable, it obviously works just fine.

Any idea what I might be doing wrong?

1

1 Answers

6
votes

I've tried your ValuesController and it works just fine.

Your problem is likely that you added the [Queryable] attribute to this action. If you use ODataQueryOptions, you don't need to use [Queryable] since you're applying the query yourself without the need for an action filter.