【发布时间】:2014-11-10 07:04:12
【问题描述】:
我升级到 OData V4,我意识到路由约定已经改变。所以不是
http://somesite.com/api/products/1
您将拥有以下内容
http://somesite.com/api/products(1)
现在这对于未来的新应用来说很好,但我们需要为旧版应用支持传统网址。有没有办法同时支持 url,或者暂时支持传统的 url?
如果我有下面的例子
[ODataRoute("{key}")]
public async Task<IHttpActionResult> Put([FromODataUri] string key, Dealer dealer)
{
// some logic code here
}
我收到以下错误
The path template '{key}' on the action 'Put' in controller 'Dealers' is not a valid OData path template. Resource not found for the segment '{key}'
【问题讨论】:
-
你试过
[ODataRoute("Products/{key}")]吗? -
是的,我有 - 还是同样的问题。
-
在 OData URL 约定中,仅支持 somesite.com/api/products(1)。我不确定“somesite.com/api/products/1”是否可以使用以前版本的 OData。您提到您“升级”到 OData V4,您是从旧 OData 版本升级还是纯 Web API 升级?
-
我以前使用 Web Api 并使用 Queryable 属性装饰控制器。我最近切换到从 OdataController 继承。 Web Api 出现问题,该属性使 $count 正常工作。
标签: c# asp.net-web-api odata