title: How limit OData results in a WebAPI
body: <p>I'm currently developing an application which uses a Web API to return data which is stored in a database.</p>
  
  <p>Now, I need to be able to filter the results, so OData to the request, that way I can built an entire filter in a query string.</p>
  
  <p>Here's the configuration of the OData:</p>
  
  <pre><code>private static void ConfigureOData(HttpConfiguration config)
  {
      ODataModelBuilder builder = new ODataConventionModelBuilder();
      builder.EntitySet&lt;GenericArticle&gt;("GenericArticle");
      config.MapODataServiceRoute(routeName: "ODataRoute", routePrefix: "OData", model: builder.GetEdmModel());
  
      // Defines the configuration for OData.
      var queryAttribute = new QueryableAttribute
      {
          MaxTop = Convert.ToInt32(ConfigurationManager.AppSettings["OData:MaxTop"]),
          PageSize = 2
      };
  
      config.EnableQuerySupport(queryAttribute);
  }
  </code></pre>
  
  <p>This method is being called from within the <code>WebApiConfig.cs</code> file.</p>
  
  <p>The <code>Global.asax</code> file does contain the following code:</p>
  
  <pre><code>protected void Application_Start()
  {
      GlobalConfiguration.Configure(WebApiConfig.Register);
      GlobalConfiguration.Configuration.EnsureInitialized();
  
      UpdateDatabaseToLatestVersion();
  }
  </code></pre>
  
  <p>The controller that I use to query the data is the following:</p>
  
  <pre><code> [EnableQuery]
   public IQueryable&lt;GenericArticle&gt; Get()
   {
       var data = UnitOfWork.GenericArticlesRepository.Entities;
  
       return data;
   }
  </code></pre>
  
  <p>So, the method is marked with the <code>EnableQuery</code> attribute and the controller does also inherit from <code>ODataController</code>.</p>
  
  <p>Now, there are some tables which I can query which contains millions of records, and off course, I don't even want a GetAll to find it's way to the database.</p>
  
  <p>Therefore, I tought that in the <code>WebApiConfig</code> file, the following code was sufficient:</p>
  
  <pre><code>var queryAttribute = new QueryableAttribute
  {
      MaxTop = Convert.ToInt32(ConfigurationManager.AppSettings["OData:MaxTop"]),
      PageSize = 2
  };
  </code></pre>
  
  <p>However, this does not limit the results, but it throws an error when I request the url with a take filter which is more than the MaxTop value defined here.</p>
  
  <p>Is there a way to ensure that, even if I request the url without any filter parameters, that the result will only contain the first 'x' records with paging enabled?</p>