在尝试标记odata时,可查询属性未在mvc 4 web api中进行编译

时间:2021-01-31 19:34:24

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

我正在使用visual studio 2012附带的MVC 4 web api。

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

据我所知,odata不会自动解析,但我们需要在行动中添加[Queryable]属性。

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.

odata仍然受支持吗?以及为什么Queryable不被识别为此处列出的属性。

Thank you

谢谢

2 个解决方案

#1


15  

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

如此处所述,OData支持已移至单独的NuGet包。

#2


12  

It's in this Assembly (DLL) :

它在这个程序集(DLL)中:

 System.Web.Http.OData.dll

This namespace :

此命名空间:

System.Web.Http.QueryableAttribute

In this nuget package :

在这个nuget包中:

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.

当我安装包但它没有显示为有效类型。即使验证System.Web.Http.OData.dll存在并在对象资源管理器中查找我也找不到它。最后我刚刚重启Visual Studio,一切都很好。我怀疑这个DLL的一些旧版本可能会混淆它或类似的东西。

#1


15  

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

如此处所述,OData支持已移至单独的NuGet包。

#2


12  

It's in this Assembly (DLL) :

它在这个程序集(DLL)中:

 System.Web.Http.OData.dll

This namespace :

此命名空间:

System.Web.Http.QueryableAttribute

In this nuget package :

在这个nuget包中:

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.

当我安装包但它没有显示为有效类型。即使验证System.Web.Http.OData.dll存在并在对象资源管理器中查找我也找不到它。最后我刚刚重启Visual Studio,一切都很好。我怀疑这个DLL的一些旧版本可能会混淆它或类似的东西。