加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-web-api – 无法为Web API OData端点解析MapODataRoute

发布时间:2020-12-16 06:26:33 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试为我的Web API服务配置OData端点,但我无法解析MapODataRoute方法.根据这个 tutorial,有关要求的说明如下: ASP.NET and Web Tools 2012.2 Update or the Microsoft ASP.NET Web API OData NuGet package. 我安装了当前的ASP.NET和Web Tools 2012.2
我正在尝试为我的Web API服务配置OData端点,但我无法解析MapODataRoute方法.根据这个 tutorial,有关要求的说明如下:

ASP.NET and Web Tools 2012.2 Update or the Microsoft ASP.NET Web API
OData NuGet package.

我安装了当前的ASP.NET和Web Tools 2012.2更新(已卸载RC版本并安装了最新版本),因此我的项目应该足够了.

但是我无法通过以下代码行:

config.Routes.MapODataRoute("ODataRoute","odata",model);

……由于以下异常:

‘System.Web.Http.HttpRouteCollection’ does not contain a definition
for ‘MapODataRoute’ and no extension method ‘MapODataRoute’ accepting
a first argument of type ‘System.Web.Http.HttpRouteCollection’ could
be found (are you missing a using directive or an assembly reference?)

我相信如果我安装NuGet包这个消息会解决(安装它没什么大不了的),但我认为所有OData支持都卷入了’ASP.NET和Web Tools 2012.2更新’,因此不需要NuGet包?有谁知道为什么MapODataRoute没有解析或我需要哪个引用?

解决方法

来自同一个教程:

If you installed ASP.NET and Web Tools 2012.2 Update,then the Web API
project template automatically includes the OData packages.

因此,检查项目的nuget包,是否存在odata包.

可能是,您安装了新版本的ASP.NET和Web Tools,然后打开旧项目.我怀疑只有在安装ASP.NET和Web Tools 2012.2更新后创建项目时才需要手动添加odata软件包.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读