title: ServiceStack AutoQuery, Implicit/Explicit Queries
body: <p>I have the following Request DTO:</p>
  
  <pre><code>[Route("/processresults")]
  public class FindProcessResults : QueryBase&lt;ProcessResult, ProcessResultDto&gt;  {}
  </code></pre>
  
  <p><code>ProcessResult</code> has a property named <code>Id</code> (Int32). I have two <code>ProcessResults</code> in my database, Id 1 and 2.</p>
  
  <p>When I perform a GET to /processresults?Id=1 I get a single <code>ProcessResult</code> returned. Great.</p>
  
  <p>However when I POST this JSON I get two <code>ProcessResults</code> returned. The query is not executing. When I add the property <code>Id</code> to <code>FindProcessResults</code> the JSON call does work, however I have not set <code>EnableUntypedQueries</code> to false.</p>
  
  <pre><code>PostData: {"Id":"1"}
  </code></pre>
  
  <p>What could be the issue here?</p>
  
  <p>Bonus points, if I make a <code>POST</code> with Form Data I get the following exception:</p>
  
  <pre><code>{
     ResponseStatus: {
       ErrorCode: "RequestBindingException",
       Message: "Unable to bind request",
       StackTrace: " at ServiceStack.Host.RestHandler.CreateRequest(IRequest httpReq, IRestPath restPath)\ \ at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)"
     }
  }
  </code></pre>
  
  <p>However if I do the same (a post) with x-www-form-urlencoded the query works as intended (returns a single result).</p>
  
  <p>Conclusion: Whilst I can resolve this issue by adding the parameter I wish to query by (Id) to the typed request, this defeats the purpose of what I am trying to achieve, a generic query mechanism for my data store. The functionality already exists for the GET version of the request.</p>
  
  <p>I believe it is to do with the implementation of AutoQueryServiceBase:</p>
  
  <pre><code>        public virtual object Exec&lt;From&gt;(IQuery&lt;From&gt; dto)
          {
              SqlExpression&lt;From&gt; q;
              using (Profiler.Current.Step("AutoQuery.CreateQuery"))
              {
                  q = AutoQuery.CreateQuery(dto, Request.GetRequestParams());
              }
              using (Profiler.Current.Step("AutoQuery.Execute"))
              {
                  return AutoQuery.Execute(dto, q);
              }
          }
  </code></pre>
  
  <p>This is using <code>Request.GetRequestParams()</code> which will return parameters from the Query String or the Form Parameters, whilst a JSON request is attempting to be deserialized into <code>&lt;From&gt; dto</code>. The <code>From</code> type <code>FindProcessResults</code> has no <code>Id</code> property and so it is not populated and passed to the Query.</p>
  
  <p><strong>Requested HTTP Request/Response:</strong></p>
  
  <p><strong>Request</strong></p>
  
  <pre><code>POST /processresults HTTP/1.1
  Host: localocl
  Accept: application/json
  Content-Type: application/json
  Cache-Control: no-cache
  Postman-Token: 36d4b37e-0407-a9b3-f2f2-5b024d7faf7f
  
  {"Id":1}
  </code></pre>
  
  <p><strong>Response</strong></p>
  
  <pre><code>Cache-Control → private
  Content-Length → 1580
  Content-Type → application/json; charset=utf-8
  Date → Mon, 03 Nov 2014 21:20:43 GMT
  Server → Microsoft-IIS/8.5
  Vary → Accept
  X-AspNet-Version → 4.0.30319
  X-Powered-By → ServiceStack/4.033 Win32NT/.NET, ASP.NET
  
  {"Offset":0,"Total":2,"Results"....
  </code></pre>