title: Manually applying OData query options using Breeze and still return InlineCount
body: <p>I'm using Breeze with a Web API back-end and I am trying to figure out how to properly apply the received OData query options while also trying to return the inlineCount for the given OData query.</p>
  
  <p>The reason I'm trying to do this is because I need to hit another datasource and fill in some associated properties on the entity that I'm returning (all while still allowing for paging and sorting).</p>
  
  <p>Here's an example of what I'm trying to do:</p>
  
  <pre><code>[HttpGet]
  public QueryResult Reservations( ODataQueryOptions options ) {    
      var set = _contextProvider.Context.Reservations.Where(r =&gt; r is ScheduledReservation || r is PoolReservation).Include(i =&gt; i.ReservationType)
                                        .Include(i =&gt; i.Vehicle)
                                        .Include(i =&gt; i.Vehicle.VehicleMake)
                                        .Include(i =&gt; i.Vehicle.VehicleModel).AsQueryable();
  
      var queryable = Breeze.WebApi.QueryHelper.ApplyQuery(set, options, new ODataQuerySettings { EnableConstantParameterization = true, EnsureStableOrdering = true, HandleNullPropagation = HandleNullPropagationOption.Default });
  
      // Hit other data source here and fill in associated properties on returned entities
  
      return new QueryResult
      {
          InlineCount = // Would like to get at breeze's execution of this query,
          Results = queryable.Cast&lt;Reservation&gt;()
      };
  }
  </code></pre>
  
  <h2><strong>How do I manually apply the query options to my Queryable while still allowing for Breeze to take care of executing and returning an inlineCount?</strong></h2>
  
  <p><strong>The problem with what I'm doing above is three-fold:</strong></p>
  
  <p>1) This is throwing an error saying that Breeze cannot create an EDM model because this action method returns a QueryResult and not something that implements IEnumerable&lt;>.</p>
  
  <p>2) I'm using Breeze's ApplyQuery() method instead of the ApplyTo() off of the ODataQueryOptions object because I am also wanting to sort on nested properties which ApplyTo() does not yet allow.  I'm not sure if I'm over-stepping my bounds by digging into Breeze's functionality and manually calling the ApplyQuery() method.</p>
  
  <p>3) I can see in EF Profiler that the query to retrieve the inlineCount is executing when calling Breeze's ApplyQuery method.  I have found that the ApplyQuery method is setting the inlineCount on the ODataQueryOptions object as a property with a key of MS_InlineCount.  So, it doesn't appear that there is an "easy" way to get at that (rather, it seems hokey for me to go pull it out of the ODataQueryOptions properties array).</p>
  
  <p>The over-arching reason why I'm asking is this whole line of thinking feels awkward.  I want to double-check and make sure I have not missed something that would allow me to easily apply the OData query to my DbSet and still allow for returning the inlineCount (and still allow for proper paging and sorting).</p>