title: OData V4 WebAPI routing convention for 'Cast'
body: <p>Building an ODataController with a base Get method for the following query:</p>
  
  <pre><code>http://localhost:8080/api/Bases
  </code></pre>
  
  <p>is quite straightforward:</p>
  
  <pre><code>[EnableQuery]
  public IHttpActionResult Get()
  {
      return Ok(new List&lt;Base&gt;());
  }
  </code></pre>
  
  <p>In the same style, I'm trying to implement the "cast" route ("~/entityset/cast"), which is defined in the <a href="http://docs.oasis-open.org/odata/odata/v4.0/os/part2-url-conventions/odata-v4.0-os-part2-url-conventions.html#_Toc372793786" rel="nofollow">OData V4 convention part 4.9</a> but this is quite undocumented. So I dug into some <a href="https://github.com/OData/WebApi/blob/master/OData/src/System.Web.OData/OData/Routing/Conventions/EntitySetRoutingConvention.cs" rel="nofollow">source code</a> and found that for the following URL:</p>
  
  <pre><code>http://localhost:8080/api/Bases/MyNamespace.DerivedA
  </code></pre>
  
  <p>I could define the following method in the same controller:</p>
  
  <pre><code>[EnableQuery]
  public IHttpActionResult GetFromDerivedA()
  {
      return Ok(new List&lt;DerivedA&gt;());
  }
  </code></pre>
  
  <p>Which works BUT I have like a dozen types that inherit from <code>Base</code>. Instead of declaring one method per derived type, is there a way I could use something like:</p>
  
  <pre><code>[EnableQuery]
  public IHttpActionResult GetFrom&lt;T&gt;()
      where T : Base
  {
      return Ok(new List&lt;T&gt;());
  }
  </code></pre>
  
  <p>I'm using:</p>
  
  <ul>
  <li>Microsoft.AspNet.WebApi 5.2.3</li>
  <li>Microsoft.OData 6.13.0</li>
  <li>Microsoft.AspNet.OData 5.6.0</li>
  </ul>
  
  <hr>
  
  <h2>Updates</h2>
  
  <p>I can create <a href="http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-routing-conventions" rel="nofollow">a new RoutingConvention</a> and have the overriden SelectAction return my generic method, but it seems I'll have to forget the generic method approach:</p>
  
  <blockquote>
    <p>"Cannot call action method <code>'System.Web.Http.IHttpActionResult GetFrom[T]()'</code> on controller 'MyProject.Controllers.BasesController'
    because the action method is a generic method."</p>
  </blockquote>
  
  <p>How about this then, is this possible?</p>
  
  <pre><code>[EnableQuery]
  public IHttpActionResult GetFrom(Type derivedType)
  {
      //snip!
  }
  </code></pre>
  
  <p>If not, any other ideas?</p>