Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Api [Queryable] attribute not recognised

I'm trying to enable OData in a Web Api class and am adding the attribute [Queryable] to my query

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

public class ItemsController : ApiController
{
    ...
    [HttpGet]
    [Queryable]
    public IQueryable<Item> GetItems()
    {
        return _repository.Items.AsQueryable();
    }

but Visual Studio tells me

'Queryable' is not an attribute"

and I get a compilation error:

CS0616: 'System.Linq.Queryable' is not an attribute class

If I qualify the attribute

[System.Web.Http.Queryable]

I get another error message

CS0234: The type or namespace name 'Queryable' does not exist in the namespace 'System.Web.Http' (are you missing an assembly reference?)

Any ideas why the [Queryable] doesn't seem to be recognised? This is a Web forms application to which Web API has been added at a later date.

like image 530
Howard Shaw Avatar asked Jan 28 '15 17:01

Howard Shaw


1 Answers

My bad, it's now in a separate Nuget package

Install-Package Microsoft.AspNet.WebApi.OData -Version 5.3.1

I do wish Microsoft would update their tutorials & docs when they do this kind of thing.

like image 119
Howard Shaw Avatar answered Nov 07 '22 12:11

Howard Shaw