Read More on Telerik Blogs
September 10, 2012 Web
Get A Free Trial

With this post I will show you how to consume Visual Studio 2012 LightSwitch OData services to enable server sorting, filtering, paging, etc. for your custom LightSwitch component:

 

1) Create new LightSwitch application, add some database connection (in my case I’m using Northwind on my SQLEXPRESS instance) and screen:

 

2) Add new separate Silverlight project (class library) with a custom UserControl to the LightSwitch application, similar to my previous blog post, and select the custom control to be used in our screen:

 

3) Add service reference to your LightSwitch application (if the application is not yet published, you can check the actual application address from your system tray icon):

 

4) Add Telerik assemblies and declare desired components. In this case I’m using RadGridView, RadDataPager and RadDataServiceDataSource:

* Because of the RadDataServiceDataSource you need to add reference to System.Data.Services.Client.dll however if you try to compile the application you will get errors due to duplicate types. To resolve these errors you can remove all references from the Silverlight class library project added automatically after the service reference

** If you do not have also latest updates, like yours truly, you will need also to change the constructor for your service context (remove the second parameter):

 

5) Setup the service URI and components and run the application to check the result:



* For every filter, sort, page, etc. you will get separate call to your database server with all needed info to apply requested operations at once:

 

Enjoy!

Download


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks