This is the eighth part of the 11 series LightSwitch tutorial. In this part we will learn about how to use WCF RIA Service as our external data source.
Table of Content
- Aim of the article
- Steps to use WCF RIA Service as the External DataSource
Rapid business application development is a need of today’s business and keeping that in focus software stewards wants to build the 3 tire applications at a lightning speed where there will be less code, less time will be spent on designing the UI screens , the BAL layer and DAL layer. By keeping all these into focus, on 26th July, 2011, Microsoft has released their new product – LightSwitch.
It is the simplest way for developers of all skill levels to develop business applications for the desktop as well as for cloud. This is the eighth part of the series of 12 LightSwitch tutorials where we will look into how to use WCF RIA service as the external datasource.
You can read the other parts of the LightSwitch tutorial as under
- Part 1: Introduction to Light Switch
- Part 2: Rapport with New Data Screen
- Part 3: Rapport with Search Data Screen
- Part 4: Rapport with Editable Grid Screen
- Part 5: Rapport with List and Details Screen
- Part 6: Rapport with Details Screen
- Part 7: Rapport with External Data Source – Database
- Part 8: Rapport with External Data Source – WCF RIA Service
- Part 9:Using a custom control in LightSwitch
- Part 10: Publish LightSwitch Application as Desktop application and host in local system
- Part 11: Publish LightSwitch Application as Web application
The article assumes that, we have LightSwitch 2011 installed in our system
Step 1: The first step in creating a LightSwitch application is to create a new project
Step 2: The Designer appears and the necessary folders for our project are added to the Solution Explorer. Close the designer
Step 3: The next step is to create a reusable WCF RIA Class Library. For that purpose, create a new Class library project
Step 4: Delete class1.cs file.Right Click->Add new item-> Ado.net Entity Data model
Step 5: Specify data source. Choose Player table
Step 6: Click Finish button.Build the project.Right Click->Add new item->Domain Service Class
Step 7: Click Add. The "Add New Domain Service Window" appears
We need the PlayerTable in the Domain Service Class. Also, un-check the "Enable client access" option as we donot need it.
Step 8: Click OK. The domain service class will be generated
// Implements application logic using the testEntities context.
// TODO: Add your application logic to these methods or in additional methods.
// TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
// Also consider adding roles to restrict access as appropriate.
// TODO: add the EnableClientAccessAttribute to this class to expose this DomainService to clients.
public class DomainService1 : LinqToEntitiesDomainService<testEntities>
// Consider constraining the results of your query method. If you need additional input you can
// add parameters to this method or create additional query methods with different names.
// To support paging you will need to add ordering to the 'PlayerTables' query.
public IQueryable<PlayerTable> GetPlayerTables()
Decorate the GetPlayerTables method with
[Query(IsDefault = true)]
Step 9: Now,choose the Appllication1 project(Light switch project) and click on "Add Data Source"
From the available Data source type, choose WCF RIA Service
Step 10 : Click On Next button
Step 11: Click Add Reference button.Choose Class Library1 project. This is our domain service.
Step 12: Click OK button and our domain service will be added to the "Available WCF RIA Service Classes" listbox
Step 13: Click Next and choose the entity
Step 14: Click Finish and we can find that our Domain Service has been added under the DataSources and the source table for our domain entity has also been added
Step 15: Now select File View
Step 16: Then click on "Show all files" option and all the files will be listed.Expand the ServerGenerated project and choose the Web.config file
Step 17: From the App.config of Class Library 1 project, copy the Connection string
And paste it to the web.config of ServerGenerated Project
And that's all. We are done.Now add a search screen and view the result
So in this part we have learn about how to use WCF RIA Service as our external data source.In the next article we will look into how to create custom control and use it in LightSwitch application.
Thanks for reading the article.Happy lightning with LightSwitch.
If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.
Found interesting? Add this to: