title: Reconstructing an ODataQueryOptions object and GetInlineCount returning null
body: <p>In an odata webapi call which returns a PageResult I extract the requestUri from the method parameter, manipulate the filter terms and then construct a new ODataQueryOptions object using the new uri.  </p>
  
  <p>(The PageResult methodology is based on this post:
  <a href="http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options" rel="nofollow noreferrer">http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options</a>  )</p>
  
  <p>Here is the raw inbound uri which includes %24inlinecount=allpages</p>
  
  <pre><code>http://localhost:59459/api/apiOrders/?%24filter=OrderStatusName+eq+'Started'&amp;filterLogic=AND&amp;%24skip=0&amp;%24top=10&amp;%24inlinecount=allpages&amp;_=1376341370337
  </code></pre>
  
  <p>Everything works fine in terms of the data returned except Request.GetInLineCount returns null.  </p>
  
  <p>This 'kills' paging on the client side as the client ui elements don't know the total number of records.  </p>
  
  <p>There must be something wrong with how I'm constructing the new ODataQueryOptions object.  </p>
  
  <p>Please see my code below.  Any help would be appreciated.  </p>
  
  <p>I suspect this post may contain some clues <a href="https://stackoverflow.com/a/16361875/1433194">https://stackoverflow.com/a/16361875/1433194</a> but I'm stumped.  </p>
  
  <pre><code>public PageResult&lt;OrderVm&gt; Get(ODataQueryOptions&lt;OrderVm&gt; options)
      {
  
          var incomingUri = options.Request.RequestUri.AbsoluteUri;
  
  //manipulate the uri here to suit the entity model   
  //(related to a transformation needed for enumerable type OrderStatusId )
  //e.g. the query string may include %24filter=OrderStatusName+eq+'Started' 
  //I manipulate this to %24filter=OrderStatusId+eq+'Started'
  
          ODataQueryOptions&lt;OrderVm&gt; options2;
  
          var newUri = incomingUri;  //pretend it was manipulated as above
  
          //Reconstruct the ODataQueryOptions with the modified Uri
  
          var request = new HttpRequestMessage(HttpMethod.Get, newUri);
  
          //construct a new options object using the new request object
          options2 = new ODataQueryOptions&lt;OrderVm&gt;(options.Context, request);
  
          //Extract a queryable from the repository.  contents is an IQueryable&lt;Order&gt;
          var contents = _unitOfWork.OrderRepository.Get(null, o =&gt; o.OrderByDescending(c =&gt; c.OrderId), "");
  
          //project it onto the view model to be used in a grid for display purposes
          //the following projections etc work fine and do not interfere with GetInlineCount if
          //I avoid the step of constructing and using a new options object
          var ds = contents.Select(o =&gt; new OrderVm
          {
              OrderId = o.OrderId,
              OrderCode = o.OrderCode,
              CustomerId = o.CustomerId,
              AmountCharged = o.AmountCharged,
              CustomerName = o.Customer.FirstName + " " + o.Customer.LastName,
              Donation = o.Donation,
              OrderDate = o.OrderDate,
              OrderStatusId = o.StatusId,
              OrderStatusName = ""
          });
  
          //note the use of 'options2' here replacing the original 'options'
          var settings = new ODataQuerySettings()
          {
              PageSize = options2.Top != null ? options2.Top.Value : 5
          };
  
          //apply the odata transformation
          //note the use of 'options2' here replacing the original 'options'    
          IQueryable results = options2.ApplyTo(ds, settings);
  
          //Update the field containing the string representation of the enum
          foreach (OrderVm row in results)
          {
              row.OrderStatusName = row.OrderStatusId.ToString();
          }
  
          //get the total number of records in the result set 
          //THIS RETURNS NULL WHEN USING the 'options2' object - THIS IS MY PROBLEM
          var count = Request.GetInlineCount();
  
          //create the PageResult object
          var pr = new PageResult&lt;OrderVm&gt;(
              results as IEnumerable&lt;OrderVm&gt;,
              Request.GetNextPageLink(),
              count
              );
          return pr;
      }
  </code></pre>
  
  <p>EDIT<br>
  So the corrected code should read</p>
  
  <pre><code>//create the PageResult object
  var pr = new PageResult&lt;OrderVm&gt;(
      results as IEnumerable&lt;OrderVm&gt;,
      request.GetNextPageLink(),
      request.GetInlineCount();
      );
  return pr;
  </code></pre>
  
  <p>EDIT<br>
  Avoided the need for a string transformation of the enum in the controller method by applying a Json transformation to the OrderStatusId property (an enum) of the OrderVm class </p>
  
  <pre><code>[JsonConverter(typeof(StringEnumConverter))]
  public OrderStatus OrderStatusId { get; set; }
  </code></pre>
  
  <p>This does away with the foreach loop.  </p>