Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Queryable attribute is not compiling in mvc 4 web api when trying to mark for odata

I'm using MVC 4 web api that comes with visual studio 2012.

As I've understand odata is not parsed automatically, but we need to add [Queryable] attribute to the action now.

So I added it:

public class TestController : ApiController
{
    [Queryable]
    public IQueryable<MyClass> GetMyClasses()
    {
       return ...;
    }
}

but I'm getting a compilation error:

The type or namespace name 'Queryable' could not be found (are you missing a using directive or an assembly reference?) 

Is the odata still supported? and why Queryable is not recognized as an attribute as listed here.

Thank you

like image 260
ozba Avatar asked Sep 23 '12 16:09

ozba


2 Answers

As explained here, OData support has been moved to a separate NuGet package.

like image 70
Darin Dimitrov Avatar answered Oct 25 '22 02:10

Darin Dimitrov


It's in this Assembly (DLL) :

 System.Web.Http.OData.dll

This namespace :

System.Web.Http.QueryableAttribute

In this nuget package :

Install-Package Microsoft.AspNet.WebApi.OData

When I installed the package however it didn't appear as a valid type. Even verifying that System.Web.Http.OData.dll was present and looking in Object Explorer I couldn't find it. Eventually I just restarted Visual Studio and everything was fine. I suspect some older version of this DLL may have been confusing it or something like that.

like image 35
Simon_Weaver Avatar answered Oct 25 '22 03:10

Simon_Weaver