【发布时间】:2014-11-14 19:34:00
【问题描述】:
OData 问题不断出现 :)
我有一个带有复合键的实体,比如这个:
public class Entity
{
public virtual Int32 FirstId { get; set; }
public virtual Guid SecondId { get; set; }
public virtual First First { get; set; }
public virtual Second Second { get; set; }
}
我创建了一个CompositeKeyRoutingConvention 来处理ODataControllers 的复合键。一切正常,除了像这样的导航链接:
http://localhost:51590/odata/Entities(FirstId=1,SecondId=guid'...')/First
我在 Firefox 中收到以下错误消息:
<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code />
<m:message xml:lang="en-US">No HTTP resource was found that matches the request URI 'http://localhost:51950/odata/Entities(FirstId=1,SecondId=guid'a344b92f-55dc-45aa-b92f-271d74643493')/First'.</m:message>
<m:innererror>
<m:message>No action was found on the controller 'Entities' that matches the request.</m:message>
<m:type></m:type>
<m:stacktrace></m:stacktrace>
</m:innererror>
</m:error>
我将 ASP.NET 源代码中的错误消息追踪到 the FindMatchingActions method in the ApiControllerActionSelector 返回一个空列表,但我对 ASP.NET 的了解到此为止。
作为参考,这是导航链接动作方法的实现(在ODataController中):
public First GetFirst(
[FromODataUri(Name = "FirstId")] Int32 firstId,
[FromODataUri(Name = "SecondId")] Guid secondId)
{
var entity = repo.Find(firstId, secondId);
if (entity == null) throw new HttpResponseException(HttpStatusCode.NotFound);
return entity.First;
}
我尝试不在FromODataUri 属性上设置名称,设置一个小写名称,我能想到的一切都是合理的。我唯一注意到的是,在使用常规 EntitySetController 时,键值的参数必须命名为 key(或 FromODataUri 属性必须将 Name 属性设置为 key),否则不会工作。我想知道这里是否也有类似的情况......
【问题讨论】:
标签: asp.net-mvc asp.net-web-api odata