Developing a LightSwitch Application in Visual Studio 2012
In this article I am going to describes the developing environment of LightSwitch in Visual Studio 2012. As we can easily create a LightSwitch application by using the Visual Studio LightSwitch 2012.
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:
- 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".
After creating the project a LightSwitch Designer will appear on the screen.
LightSwitch Designer consists of the following two options:
- we can create a new table for our application.
- we can also attach an external database.
Now we will see that Solution Explorer consists of a list of the following items along with two folders:
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.
When we click on "Create new table" we will get the following image:
Each table consists of an "Id" that is automatically assigned and is also a "Primary Key" of the table.
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.
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.
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.
"Properties" are those where you set properties for various items.
When we run the UI screen we get the following.
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.
In the following step we insert a record of another user; for that we create a new contact table.
In Light Switch validations are automatically applied to the table. We do not need to apply any kind of validation on their own.