title: ASP.NET Web API OData: Navigation Links when using Composite Keys
body: <p>The OData questions keep coming :)</p>
  
  <p>I have an Entity with a composite key, like this one:</p>
  
  <pre><code>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; }
  }
  </code></pre>
  
  <p>I created a <a href="http://code.msdn.microsoft.com/Support-Composite-Key-in-d1d53161" rel="nofollow">CompositeKeyRoutingConvention</a> that handles the composite keys for <code>ODataController</code>s. Everything is working, except Navigation Links like this one:</p>
  
  <pre><code>http://localhost:51590/odata/Entities(FirstId=1,SecondId=guid'...')/First
  </code></pre>
  
  <p>I get the following error message in Firefox:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"&gt;
    &lt;m:code /&gt;
    &lt;m:message xml:lang="en-US"&gt;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'.&lt;/m:message&gt;
    &lt;m:innererror&gt;
      &lt;m:message&gt;No action was found on the controller 'Entities' that matches the request.&lt;/m:message&gt;
      &lt;m:type&gt;&lt;/m:type&gt;
      &lt;m:stacktrace&gt;&lt;/m:stacktrace&gt;
    &lt;/m:innererror&gt;
  &lt;/m:error&gt;
  </code></pre>
  
  <p>I traced the error message in the ASP.NET source code to <a href="http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Http/Controllers/ApiControllerActionSelector.cs" rel="nofollow">the FindMatchingActions method in the ApiControllerActionSelector</a> returning an empty list, but my knowledge of ASP.NET ends there.</p>
  
  <p>For reference, this is the implementation of the navigation link action method (in an <code>ODataController</code>):</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>I tried not setting a name at the <code>FromODataUri</code> attribute, setting a lowercase name, everything sensible I could think of. The only thing I noticed is when using a regular <code>EntitySetController</code> is that the arguments for the key value have to be named <code>key</code> (or the <code>FromODataUri</code> attribute has to have the Name property set to <code>key</code>), otherwise it won't work. I wonder if something like this is the case here as well...</p>