public IEnumerable ComposeQuery(IEnumerable rootedQuery, string url)
                {
                    var urlComposer = new UrlQueryComposer();

                    // We already know it's an IQueryable.
                    var elementType = rootedQuery.GetType().GetGenericArguments()[0];

                    // To retrieve the actual count without Take/Skip, remove those
                    // arguments from the query string and execute the count using
                    // the query translator too.
                    var queryString = HttpUtility.ParseQueryString(new Uri(url).Query);

                    queryString.Remove("$skip");
                    queryString.Remove("$top");
                    var filteredUri = new UriBuilder(url);

                    filteredUri.Query = queryString.ToString();

                    var resultForCount = urlComposer.ComposeQuery(rootedQuery, filteredUri.Uri.AbsoluteUri);
                    var count          = CountMethod.MakeGenericMethod(elementType).Invoke(null, new object[] { resultForCount });

                    // Ensure limit is not exceeded.
                    queryString = HttpUtility.ParseQueryString(new Uri(url).Query);
                    var topLimit = (int)CallContext.LogicalGetData(QueryLimitData);
                    var top      = topLimit;

                    if (int.TryParse(queryString["$top"], out top))
                    {
                        if (top > topLimit)
                        {
                            top = topLimit;
                        }
                    }
                    else
                    {
                        top = topLimit;
                    }

                    queryString["$top"] = top.ToString();

                    var sanitizedUri = new UriBuilder(url);

                    sanitizedUri.Query = queryString.ToString();

                    var result = urlComposer.ComposeQuery(rootedQuery, sanitizedUri.Uri.AbsoluteUri);

                    CallContext.LogicalSetData(TotalCountHeader, count.ToString());

                    return(result);
                }
				public IEnumerable ComposeQuery(IEnumerable rootedQuery, string url)
				{
					var urlComposer = new UrlQueryComposer();

					// We already know it's an IQueryable.
					var elementType = rootedQuery.GetType().GetGenericArguments()[0];

					// To retrieve the actual count without Take/Skip, remove those 
					// arguments from the query string and execute the count using 
					// the query translator too.
					var queryString = HttpUtility.ParseQueryString(new Uri(url).Query);
					queryString.Remove("$skip");
					queryString.Remove("$top");
					var filteredUri = new UriBuilder(url);
					filteredUri.Query = queryString.ToString();

					var resultForCount = urlComposer.ComposeQuery(rootedQuery, filteredUri.Uri.AbsoluteUri);
					var count = CountMethod.MakeGenericMethod(elementType).Invoke(null, new object[] { resultForCount });

					// Ensure limit is not exceeded.
					queryString = HttpUtility.ParseQueryString(new Uri(url).Query);
					var topLimit = (int)CallContext.LogicalGetData(QueryLimitData);
					var top = topLimit;

					if (int.TryParse(queryString["$top"], out top))
					{
						if (top > topLimit)
							top = topLimit;
					}
					else
					{
						top = topLimit;
					}

					queryString["$top"] = top.ToString();

					var sanitizedUri = new UriBuilder(url);
					sanitizedUri.Query = queryString.ToString();

					var result = urlComposer.ComposeQuery(rootedQuery, sanitizedUri.Uri.AbsoluteUri);

					CallContext.LogicalSetData(TotalCountHeader, count.ToString());

					return result;
				}