Data Entities Creation in LightSwitch 2012

This article describes how to create a new data table in LightSwitch using Visual Studio 2012.

Procedure for creating a new Data Entity in LightSwitch.

Step 1

Open the Solution Explorer in Visual Studio LightSwitch 2012.

sol ex.jpg

The Application consists of two the following folders:

1. Data Sources: This stores all the entities.

2. Screens: This is used to store all the screens.

Step 2

Right-click on Data Source and choose "Add Table".

Add table.jpg

Another way to create a Table.

create new table.jpg

The default table appears in the table designer as shown below.

Empty Table.jpg

Step 3

Click on "<Add Property>" and add the following fields in the table along with their data types.

student tab.jpg

Step 4

Now we will add another table. 

add table1.jpg

The table appears in the table designer.

Subject.jpg

To add a relationship between the two tables click on the "Relationship" button.

Add Relationship.jpg

The Add New Relationship dialog box appears on the screen.

add new relationship dialog box.jpg

The dialog box consists of two sections, one is the "From" and the other is the "To" section.

In the From section I have used the "Subject" table and in the "To" section I have used the "Student" table.

Next is the Multiplicity section. In this section one Student can have many Subjects.

The next option is "On Delete Behaviour"; this drop down list consists of the following two options:

Restricted: Record in Student cannot be deleted, if there is any associated record present in the Subject Table

Cascade Delete: If a record in the Student Table is deleted then delete all the associated records from the Subject Table.

Once you have selected the tables and set the properties between the two tables then click "OK". A relationship will be established as shown below.

relationship shown.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all