How to Connect an External Data Source With LightSwitch Beta 2 - Part II



Prologue:

In Part I we saw how to connect the external database with a LightSwitch application. In this Part we shall see how to connect a LightSwitch application with a WCF RIA Service as an External Data Source.

Preparing the Solution:

Fire up the Visual Studio 2010; select LightSwitch from the Installed Project Template.

LightSwitch1.gif

Give the project name as ExternalDSWithLS and click OK to start the application development.

Adding External Data Source:

Now we will see how to add an external data source for our LightSwitch application.

LightSwitch2.gif

After preparing the solution, you will see the folder like icon with name "Data Source".

Right click on the Data Source then select Add Data Source. It will display a wizard as shown below.

Selecting Data Source Type:

The wizard with those three types of Data Sources mentioned above will be displayed after selecting the Add Data Source option.

LightSwitch3.gif

In this wizard, select the WCF RIA Services Icon which is marked with an eclipse and continue by pressing the Next button.

Adding/Selecting RIA Service:

In this wizard, you have to select the Add Reference button [No: 1], and browse the directory where the LightSwitchRIAService.Web project is to select the LightSwitchRIAServices.Web.dll file.

LightSwitch4.gif

Select the Service reference [No: 2] to add to the LightSwitch application.

Choose the Entity:

At last you have to choose the Entity from the Entity Model.

LightSwitch5.gif

To ensure the Entity Model is added with our LightSwitch application as an external data source you will be getting the table structure in the screen as in the picture shown below.

LightSwitch6.gif

Important point to remember:

  • Copy the ConnectionString from LightSwitchRIAService.Web project App.Config file and paste it into ServerGenerated project Web.Config file.
  • Usually in LightSwitch application the Solution Explorer view is a Logical View. In this view you can't see the ServerGenerated Project.
  • So what you should to do is change the Solution Explorer Logical view to File view and make all files visible [by default it is hidden].

Now you are at the End. Press F5.

Get the output screen.

LightSwitch7.gif

Summary:

In this Part II, we have seen the basics of adding a WCF RIA Service as an external Data Source to a LightSwitch Application.

Thanks for spending your precious time here. Please provide your valuable feedbacks and comments, which enable me to give a better article the next time.

Please Rate this Article!

Thanks.

Up Next
    Ebook Download
    View all
    Learn
    View all