Ordering and Paging using LightSpeed

Earlier we talked about how LightSpeed makes querying easy by using the Query object and Query Expressions. There are two other concerns which are quite important when querying which I thought we should mention and can be managed through the Query object, Ordering and Paging of your result sets.

Ordering

Ordering helps you sort results for use and this is a standard aspect in any database SQL. LightSpeed lets you specify one or more ordering clauses through the Query object.
To apply an Ordering, you use an instance of the Order object. We have provided an easy way to construct these in an expressive fashion through use of the static By method which will construct a new Order instance configured for use. This can be expanding on by successive calls to the AndBy method.

e.g.

Query.Order = Order.By(“Name”);
Query.Order = Order.By(“Name”).AndBy(“Description”);

The default sort order is Ascending which will be applied based on the type of the property being sorted, however you can change this to descending order by using the Descending() method as part of expressing your ordering.

e.g.

Query.Order = Order.By(“Name”).Descending();

Paging

Paging is an important aspect of data management, particularly when you are dealing with stateless applications such as web apps where the data context needs to be reconstructed for every query.
Paging lets you manage how much data is being returned from the database to optimize it for display where typically when faced with large data volumes we break up the results into pages of data. Paging can be performed either client side (once you know how much data you have and how you want to display it), or server side (if you know your display parameters in advance). The benefit of server side paging is that only the requested page of data is returned over the wire between your database and your application – so we should always try to do this :)
As part of the Query object, you can specify paging details for LightSpeed, and it will work to perform server side paging as supported by the query provider. Currently all providers we support handle this!
To specify paging, you need to provide an instance of the Page class configured either with an offset (Skip) or a limit for the number of records to be returned (Limit) or both (At).

e.g.

Query.Page = Page.Skip(10);
Query.Page = Page.Limit(5);
Query.Page = Page.At(10,5);

So now we know all about querying in LightSpeed and how to customize the behavior of our result sets.

Remember to check the query samples which are installed along with LightSpeed for many more examples of querying :)

kick it on DotNetKicks.com

Tagged as LightSpeed

One Response to “Ordering and Paging using LightSpeed”

  • This is interesting and almost helpful. How would this be supported in an abstracted service class?

  • Leave a Reply

Archives

Join our mailer

You should join our newsletter! Sent monthly:

Back to Top