Consuming LightSwitch OData services with Microsoft Visual Studio 2012 and Telerik RadDataServiceDataSource

by Vladimir Enchev | Comments 5

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:

image

image

image

image

image

 

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:

image

image

 

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):

image

image

image

 

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

image

* 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

image

image

** 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):
image

 

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

image

image

image

* 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:

image

image

 

Enjoy!

Download

,
Senior Technical Architect

5 Comments

paul van bladel
Wow, this is cool.
Going via the odata service gives much more control over the Telerik part.
The flickering when using the control as described in your previous post, is a showstopper.
Congratulations !
paul van bladel
It would be very useful to have a similar example (via the odata service) for the RadTreeView.
Dan
Great post!
Is there an easy way with this approach to also get the distinct values list (all records) of the column stack filter populated from server side? I did see various posts for this based on domainsource but unfortunately not for oData.
One more question: When using a child entity on my Lightswitch screen together with this odata based SL custom control, how can I synchronize the selecteditem of the RadGridView and this child entity LS control? I have only seen posts for this binding the SL control directly to the LS screen what does not give me the server side paging/filtering option.
Thank you so much for your kind support.
Vlad
Hi Dan,
Unfortunately distinct values are not supported in WCF Data Services - you will need custom method on the server (you can call it on DistictValuesLoading event of the grid). Have you tried to bind (TwoWay) SelectedItem property of the grid to your Lightswitch properties? 
Dan
Hi Vlad,
Meanwile I could manage to retreive the distinct values list as described by you.I used a direct ADO.NET LINQ call to the LS app database which allowed me to use the DISTINCT() method.
Regarding my second question I am still struggling to find a solution. The datagrid itemssource in my SL user control is not bound to the Lightswitch screen but directly to the LS database via the new built-in oDATA interface. This is for making use of completely server side filtering and paging and works perfectly. The problem I have is that I want to use a standard details(child) grid on my LS screen which is related (in sync) with the selecteditem of the custom grid in my SL user control. Of course in the end I use the same source collection but one time via a query on the LS screen and one time directly from the LS data store. This makes me think I cannot easily bind the two selecteditem properties with each other.
Thanks a lot for your ideas.

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by Vladimir Enchev - or - read latest articles in Developer Tools