LINQ Cookbook, Recipe 7: Selecting Pages of Data from Northwind (Jonathan Aneja)http://blogs.msdn.com/b/vbteam/archive/2007/07/12/linq-cookbook-recipe-7-selecting-pages-of-data-from-northwind.aspxIngredients:
- Visual Studio 2008 (Beta2 or Higher)
- Connection to Northwind database
Categories: LINQ-To-Objects, LINQ-To-SQL
Instructions:
· Create a new Windows Forms project with a Northwind DataContext (for step-by-step instructionsen-USTelligent Evolution Platform Developer Build (Build: 5.6.50428.7875)re: LINQ Cookbook, Recipe 7: Selecting Pages of Data from Northwindhttp://blogs.msdn.com/b/vbteam/archive/2007/07/12/linq-cookbook-recipe-7-selecting-pages-of-data-from-northwind.aspx#4141514Tue, 31 Jul 2007 06:42:02 GMT91d46819-8472-40ad-a661-2c78acb4018c:4141514VBTeam<p>Ralf - You can download Beta2 from <a rel="nofollow" target="_new" href="http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx">http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx</a></p>
<p>Adam - C# supports Skip/Take through extension method syntax, but it doesn't have query comprehensions for these operators.</p>
<p>Hope that helps,</p>
<p>Jonathan</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=4141514" width="1" height="1">re: LINQ Cookbook, Recipe 7: Selecting Pages of Data from Northwindhttp://blogs.msdn.com/b/vbteam/archive/2007/07/12/linq-cookbook-recipe-7-selecting-pages-of-data-from-northwind.aspx#4125107Mon, 30 Jul 2007 07:03:12 GMT91d46819-8472-40ad-a661-2c78acb4018c:4125107Adam Herscher<p>Is there a C# equivalent to skip/take?</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=4125107" width="1" height="1">re: LINQ Cookbook, Recipe 7: Selecting Pages of Data from Northwindhttp://blogs.msdn.com/b/vbteam/archive/2007/07/12/linq-cookbook-recipe-7-selecting-pages-of-data-from-northwind.aspx#4026798Tue, 24 Jul 2007 14:11:14 GMT91d46819-8472-40ad-a661-2c78acb4018c:4026798Ralf Ehlert<p>You speak at the beginning from Visual Studio 2008 Beta 2 - then it will be published?</p>
<p>Thanks for the information.</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=4026798" width="1" height="1">re: LINQ Cookbook, Recipe 7: Selecting Pages of Data from Northwindhttp://blogs.msdn.com/b/vbteam/archive/2007/07/12/linq-cookbook-recipe-7-selecting-pages-of-data-from-northwind.aspx#4014613Mon, 23 Jul 2007 22:33:55 GMT91d46819-8472-40ad-a661-2c78acb4018c:4014613Luc Peeters<p>Hi,</p>
<p>I can't figure out how to write a dynamic orderby ( sortColumns ) statement. Please assit me !</p>
<p>Regards,</p>
<p>Luc</p>
<p>&lt;System.ComponentModel.DataObject(True)&gt; _</p>
<p>Public Class ProductFacade</p>
<p> &nbsp; &nbsp;Dim DataContext As New DataClasses1DataContext</p>
<p> &nbsp; &nbsp;&lt;System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select)&gt; _</p>
<p> &nbsp; &nbsp;Public Function GetAllProducts(ByVal sortColumns As String, ByVal maximumRows As Int32, ByVal startRowIndex As Int32) As IEnumerable(Of Product)</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp;Return From p In DataContext.Products.Skip(startRowIndex).Take(maximumRows)</p>
<p> &nbsp; &nbsp;End Function</p>
<p> &nbsp; &nbsp;Function GetAllProductsCount(ByVal sortColumns As String, ByVal maximumRows As Int32, ByVal startRowIndex As Int32) As Integer</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp;Return DataContext.Products.Count</p>
<p> &nbsp; &nbsp;End Function</p>
<p>End Class</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=4014613" width="1" height="1">re: LINQ Cookbook, Recipe 7: Selecting Pages of Data from Northwindhttp://blogs.msdn.com/b/vbteam/archive/2007/07/12/linq-cookbook-recipe-7-selecting-pages-of-data-from-northwind.aspx#3955798Thu, 19 Jul 2007 17:11:05 GMT91d46819-8472-40ad-a661-2c78acb4018c:3955798Bart<p>Joku,</p>
<p>U have no clue what your talking about. &nbsp;6 pages of data...LOL. &nbsp;Try writing a Business Intelligence application when your talking about searching/filtering/paging 400,000 records...you change your opinion very quickly on how much data is acceptable to be sent over the wire.</p>
<p>Paging is not that complex, there are many samples of custom paging controls and even in VS 2008 Orcas there is a DataPager control all ready to be customized and AJAX enabled for a &quot;user friendly&quot; set up.</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=3955798" width="1" height="1">re: LINQ Cookbook, Recipe 7: Selecting Pages of Data from Northwindhttp://blogs.msdn.com/b/vbteam/archive/2007/07/12/linq-cookbook-recipe-7-selecting-pages-of-data-from-northwind.aspx#3895308Mon, 16 Jul 2007 16:48:23 GMT91d46819-8472-40ad-a661-2c78acb4018c:3895308JR Thomas<p>Already covered this solution 3 months ago in a object agnostic way a few weeks ago. Yours is centered on a product type which is only as useful as the product entity is. Why rewrite what you can use over and over again:</p>
<p><a rel="nofollow" target="_new" href="http://foreachdev.net/blog/2007/04/29/linq-paging/">http://foreachdev.net/blog/2007/04/29/linq-paging/</a></p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=3895308" width="1" height="1">re: LINQ Cookbook, Recipe 7: Selecting Pages of Data from Northwindhttp://blogs.msdn.com/b/vbteam/archive/2007/07/12/linq-cookbook-recipe-7-selecting-pages-of-data-from-northwind.aspx#3875060Sun, 15 Jul 2007 11:59:04 GMT91d46819-8472-40ad-a661-2c78acb4018c:3875060Joku<p>Paging rant:</p>
<p>&quot;The typical solution for this is to show one “page” worth of data at a time, and then give the user the ability to move to the next page. &nbsp;This results in a faster application which is easier for your customers to use&quot;</p>
<p>You forgot to mention the &quot;typical solution&quot; (99.99%) runs actually counter to the faster application and easier to use assertion.</p>
<p>Assume a 100 page word document, modify Word so that each page is fetched separately from the source location (say a shared cd over network to give it some Internet like latency). Now add a button that must be clicked to get to next and previous page. Don't give ability for going to specific page in one click. Limit find/seach queries to only happen once every x minutes per user to keep the remote resource available.</p>
<p>Now there's your typical database app in the real world. It's much more server resource intensive, much less user friendly etc.</p>
<p>So please don't ever give samples of how to do paging in naive way since it's just bad for every party involved.</p>
<p>In most cases the queries aren't that complex that it makes any difference to retrieve 1 page of records (20) rather than say 6+ pages at once to get rid of the next/previous button approach of browsing the data. If your server dies to retrieving 6+ at once vs 1 then you have issue in database design.</p>
<p>Obviously doing paging properly quickly becomes a very very complex problem, one that even Adobe hasn't solved properly yet if you look at their PDF streaming - it's just not as good as it could be yet. And Microsoft hasn't even attempted to solve it - take a look at their forums - all use the naive approach.</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=3875060" width="1" height="1">re: LINQ Cookbook, Recipe 7: Selecting Pages of Data from Northwindhttp://blogs.msdn.com/b/vbteam/archive/2007/07/12/linq-cookbook-recipe-7-selecting-pages-of-data-from-northwind.aspx#3835774Thu, 12 Jul 2007 22:31:45 GMT91d46819-8472-40ad-a661-2c78acb4018c:3835774Bill_McC<p>Not keen on the requirement ot have Strict Off for this example. &nbsp;</p>
<p>Apart from that, it's cool to see the SQL this generates:</p>
<p><a rel="nofollow" target="_new" href="http://msmvps.com/blogs/bill/archive/2007/07/13/inside-recipe-7.aspx">http://msmvps.com/blogs/bill/archive/2007/07/13/inside-recipe-7.aspx</a></p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=3835774" width="1" height="1">