I am writing a wpf destop application, and would like to use SQL Server CE as a backend. I\'m trying to come up with a good way to do efficient data paging. In SQL Server
I'm also currently working on a WPF application which uses SQL Server CE as the persistence mechanism. We have several (40+) tables and some of them are pretty big (50k records, at least that's big for my standards).
My advice about data paging directly in SQL CE is this: avoid it if you can! I have used the approach described by Bob King, and at least for me it resulted in Very Ugly code, a real maintenance nightmare.
Unless you'll need to page over tens of thousands of records, I believe the best approach is to load them all using SqlCeDataReader into a collection of custom classes and then page over the collection in memory. I found this approach to be more responsive than re-executing the SQL query every time, even with caching. What happened is that in my case the queries were fairly complex, and SqlCeDataReader performance was good enough so that the performance hit was almost imperceptible. No need to point that, after the first batch load, every page change happens almost instantaneously because everything is kept in memory.
The general opinion of my users were that it's ok to wait a little longer for the first results to appear, if that's going to lead to faster paging afterwards. And using LINQ, paging is as easy as calling Skip and Take methods. I have implemented this logic inside a Pager