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来处理ODataController
s 的复合键。一切正常,除了像这样的导航链接:
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 源代码中的错误消息跟踪到ApiControllerActionSelector 中的 FindMatchingActions 方法返回一个空列表,但我对 ASP.NET 的了解到此为止。
作为参考,这是导航链接操作方法的实现(在 an 中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
),否则它将不起作用。我想知道这里是否也有类似的情况......