title: DevExpress MVC GridView BindToLINQ() Selects Too Much Data
body: <p>When using the devexpress gridview's bindtoLINQ functionality it queries the entire table set instead of the page the client is looking at.</p>
  
  <p>IE. using SQL Server Profiler, we see it selects all columns of the 200k+ rows in the table instead of just the intended 10.</p>
  
  <p>The view looks like this:</p>
  
  <pre><code>@Html.DevExpress().GridView(...).BindToLINQ("MyProject.Models.DBEntities", "myTable", (s, e) =&gt; { e.KeyExpression = "row_id"; }).GetHtml()
  </code></pre>
  
  <p>The grid does come out well-formatted client-side but since it appears to select the entire dataset inside my table any type of action the client executes will perform way too poorly- just going to the next page will take approx. 15 seconds. Why doesn't the gridview use a LIMIT and pagerow to only select the necessary data that is visible to the client? It only seems to use the Linq Skip and Take commands after selecting the entire table contents.</p>
  
  <p>This is another way I tried it but it behaves similarly:</p>
  
  <pre><code>// the ActionResult function inside my controller:
  public ActionResult GridViewPartial() {
    DBEntities dbEntities = new DBEntities();
    var myLinqQuery = from s in dbEntities.myTable select new { s.row_id, s.row_username };
  
    return PartialView("GridViewPartial", myLinqQuery);
  }
  
  // inside the Razor view:
  @model IQueryable
  @Html.DevExpress().GridView(...).BindToLINQ("", "", (s, e) =&gt; { e.KeyExpression = "row_id"; e.QueryableSource = Model; }).GetHtml()
  </code></pre>
  
  <p>Alternatively, using Bind() instead of BindToLINQ() does the same thing:</p>
  
  <pre><code>// inside the Razor view:
  @model IQueryable
  @Html.DevExpress().GridView(...).Bind(Model).GetHtml()
  </code></pre>