In this article we are going to see how to work with Database and Tables to store the data and manipulate it in Visual Studio Light Switch Application. In our earlier article, we have seen the different screen templates that are available with the Light Switch application and also saw some examples on how to use the same. In our earlier article we have seen the step by step approach on creating a Visual Studio Light Switch Application where we created a simple table to store the data. With this tutorial we will see how we can make use of most of the available options to create and manipulate a table for a Visual Studio Light Switch Application.
Open Visual Studio 2012 IDE in administrator mode and create a new LightSwitch Project as shown in the screen below.
Now follow the steps from the Part 2 of this series and create a simple application which get the data and save it to the database table as shown in the screen below.
This application is a simple Light Switch app which gets the students data and save it to the table which we created. The table structure looks like below.
Now let us use some of the features of the Light Switch Create table screen, like we will add a dependency relationship for the department as we need to specify which department the students belong to. To start with first right click on the Application Data folder in the solution explorer and click Add Table and create a new DepartmentTable as shown in the screen below.
Now go to the let us add the data for the DepartmentTable by simply creating a List screen and add 2 to 3 departments as shown in the screen below. To add just right click on the Screen folder in solution explorer and select the appropriate screen.
Now we added few data as Department let us use this in our Student table, to do that open Student table in the designer view and click on Relationships and add the Many to 1 relationship between Student and Department tables as shown in the screen below.
Now right click on the Screen folder and create a new Screen which is List and details view with selecting the Students Table as the data source as shown in the screen below.
We are done with our design and we can execute the project and we can see the relationship between the 2 tables in a form of a combo box which holds the department details as shown in the screen below.
We can do any number of relationships between the tables and get a good normalized solution in place for the application which we are architecting with Visual Studio Light Switch application development. Once we select the relationship value and add it to the table it looks a normalized way of handling the relationship between the tables added neatly as shown in the screen below.
So in this article we have seen how to develop a Visual Studio 2012 Light Switch application which is having a relational data splitted across 2 different tables.