title: .Net WebApi OData Actions that return an Queryable
body: <p>I want to achieve something close to the RateProduct action described in: <a href="http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-actions">http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-actions</a></p>
  
  <p>In that tutorial it is defined as:</p>
  
  <pre><code>[HttpPost]
  public int RateProduct([FromODataUri] int key, ODataActionParameters parameters) 
  { 
      // ...
  }
  
  ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
  modelBuilder.EntitySet&lt;Product&gt;("Products");
  
  // New Code
  ActionConfiguration rateProduct = modelBuilder.Entity&lt;Product&gt;().Action("RateProduct");
  rateProduct.Parameter&lt;int&gt;("Rating");
  rateProduct.Returns&lt;int&gt;();
  </code></pre>
  
  <p>However, I have the use case of a Location entity that is smart enough to return other Locations within a certain radius around it.  It should roughly be like this:</p>
  
  <pre><code>[HttpPost]
  public IQueryable&lt;Location&gt; GetLocationsWithinRadius([FromODataUri] int key, ODataActionParameters parameters) 
  { 
      // Get the Location instance intended to be the center of the radius by using the key
      // Do a radius search around it using (int)parameters["radius"] as the radius
      // return the IQueryable&lt;Location&gt; of all location found within that radius
  }
  
  ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
  modelBuilder.EntitySet&lt;Location&gt;("Locations");
  
  // New Code
  ActionConfiguration getLocations = modelBuilder.Entity&lt;Location&gt;().Action("GetLocationsWithinRadius");
  getLocations.Parameter&lt;int&gt;("radius");
  getLocations.Returns&lt;IQueryable&lt;Location&gt;&gt;();
  </code></pre>
  
  <p>I would love to get this to work and currently it doesn't work when the the return type is an <code>IQueryable&lt;Location&gt;</code>.  If the return type is a primitive like an int, then it works, otherwise it gives the following error when I create a post in fiddler (the post is something like <code>http://localhost:2663/odata/Locations(2112)/GetLocationsWithinRadius</code> and the Request Body is <code>{radius: 50}</code>):</p>
  
  <pre><code>{
    "odata.error":{
      "code":"","message":{
        "lang":"en-US","value":"An error has occurred."
      },"innererror":{
        "message":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; odata=minimalmetadata; streaming=true; charset=utf-8'.","type":"System.InvalidOperationException","stacktrace":"","internalexception":{
          "message":"The related entity set could not be found from the OData path. The related entity set is required to serialize the payload.","type":"System.Runtime.Serialization.SerializationException","stacktrace":"   at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(Object graph, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)\r\n   at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.&lt;&gt;c__DisplayClassa.&lt;WriteToStreamAsync&gt;b__9()\r\n   at System.Threading.Tasks.TaskHelpers.RunSynchronously(Action action, CancellationToken token)"
        }
      }
    }
  }
  </code></pre>
  
  <p>Is it possible to do what I am trying to accomplish?  And if it is, dare I ask if the returned <code>IQueryable&lt;Location&gt;</code> becomes composable with odata paramaters...(that would be nice)?</p>
  
  <p>Thanks</p>