Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not convinced either of your links demonstrate efficent paging</p> <p><strong><a href="http://www.codeproject.com/Articles/170921/MvcContrib-Grid-Paging-and-Searching-in-ASP-NET-MV" rel="nofollow noreferrer">link 1</a> - the LINQ example</strong> In order for this to be effificent I would expect to see something in the form</p> <pre><code>var myDataSource = data.Select(x =&gt; x.Parameter = "input").Skip(1).Take(10); </code></pre> <p>The principle is that the skip and take methods just retrieve the page of data that you want</p> <p><strong><a href="http://blogs.msdn.com/b/codefx/archive/2009/09/07/how-to-implement-insert-edit-delete-paging-and-sorting-functions-in-an-asp-net-gridview-control.aspx?CommentPosted=true#commentmessage" rel="nofollow noreferrer">link 2</a> - the SQL Example</strong></p> <p>Again not convinced - I would expect to see something in the SQL that uses <code>ROW_OVER()</code> or some other evidence of the SQL only bringing back the page of data that you want. This <a href="http://blog.sqlauthority.com/2007/06/11/sql-server-2005-t-sql-paging-query-technique-comparison-over-and-row_number-cte-vs-derived-table/" rel="nofollow noreferrer">link</a> gives an example of using ROW_OVER with SQL Server 2005 (2008 might have improved - i don't know TBH - someone else might and i would be interested).</p> <p><strong>Generally</strong></p> <p>I you have ASP.Net 3.5 or higher I would use the LINQ example - it's a lot more straight forward than trying to do it in SQL</p> <p>This <a href="http://mosesofegypt.net/post/Building-Custom-Paging-with-LINQ2c-ListView2c-DataPager-and-ObjectDataSource.aspx" rel="nofollow noreferrer">link</a> gives a better example using LINQ with the Take and Skip operators to do efficient paging with a ListView. It also addresses the issue of having to get a total count of your records in order to display the number of pages which is a common requirement.</p> <p>Also - this <a href="https://stackoverflow.com/questions/548475/efficient-way-to-implement-paging">SO question</a> gives some very good examples of efficient paging so I do recommend you read that.</p> <p><strong>LINQ Caution</strong></p> <p>As the commenter below pointed out - you need to ensure that skip and take are executing on the DB not the entire dataset being realised, brought back and the Skip and Take executing on the client. Profiler is your friend here. Also is worth knowing which operators realise the query and fire it off to the database.</p> <pre><code>var myDataSource = data.Select(x =&gt; x.Parameter = "input").Skip(1).Take(10); </code></pre> <p>above probably OK </p> <pre><code>var myDataSource = data.Select(x =&gt; x.Parameter = "input") .ToList().Skip(1).Take(10); </code></pre> <p>Ooops no good. The ToList() method will cause the SQL to be fired off to the database before Skip and Take has done it's work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload