Developing a LightSwitch Application in Visual Studio 2012

Introduction

In this article I describe the LightSwitch development environment in Visual Studio 2012. We can easily create a LightSwitch application using Visual Studio LightSwitch 2012.

LightSwitch Development in Visual Studio 2012

Visual Studio LightSwitch automatically creates the User Interface for a DataSource without manually writing any code.

In order to begin our work with LightSwitch 2012 we will perform the following steps:

Step 1

  • Open the Visual Studio 2012.
  • Go to "File" => "New" => "Project..."
  • In "New Project" => "Installed" => "Template"
  • In "Template" => "LightSwitch"
  • Select "LightSwitch Application (Visual C#)".
  • Enter the Name and choose the location.
  • Click "OK".

Image 1

developlight12.jpg

Step 2

After creating the project a LightSwitch Designer will appear on the screen.

Image 2

Developing LIght1.jpg

LightSwitch Designer consists of the following two options:

  • we can create a new table for our application.
  • we can also attach an external database. 

Step 3

Now we will see that Solution Explorer consists of a list of the following items along with two folders:

  • Data Sources
  • Screens

Here the "Data Sources" folder is used to store user data i.e. "Database Tables" and the "Screens" folder is used where we can create the user interface for our application.

Image 3

 developLight3.jpg

Step 4

When we click on "Create new table" we will get the following image:

Image 4

developlight14.jpg

Each table consists of an "Id" that is automatically assigned and is also a "Primary Key" of the table.

Step 5

First we will rename the title of the table from "Table" to "ContactTable". Now we will add four additional columns called "Name", "Email", "Age" and "Address" to our table.

Image 5

lightdevelop15.jpg

Step 6

In order to insert the record we need to create a User Interface screen. When we right-click on the "Screens" Folder we will click on "Add New." It will open the "Add New Screen" dialog window. As the window opens we will select "New Data Screen" from the Screen Template, we will also provide a Screen Name to our screen and choose the database table.

Image 6

Developlight7.jpg 

In order to continue we will Click on the "Ok" button. This will create a new UI screen for inserting a new data record by a user. 

Image 7

developlight17.jpg

 

"Properties" are those where you set properties for various items.

Image 8

develop light.jpg

Step 7

When we run the UI screen we get the following.

Image 9

img 21.jpg

Step 8

Now we are able to insert a new record without writing any code. We don't need to create anything since Visual Studio LightSwitch automatically creates the screen for us with "Save" and "Refresh" buttons.

Image 10

developlight19.jpg

Step 9

In the following step we insert a record of another user; for that we create a new contact table.

Image 11

 lightimg20.jpg

Step 10

In Light Switch validations are automatically applied to the table. We do not need to apply any kind of validation on their own.

Up Next
    Ebook Download
    View all
    Learn
    View all