Data Relationship in LightSwitch

Visual Studio LightSwitch is a Microsoft tool for building business applications. There are many possible relationships in LightSwitch. A relationship is a structure of data consisting of an unordered set of tuples which share the same type. A relation has zero or more values. There are three types of relations in LightSwitch, which are as follows.

One to one

One-to-one relationships is a small type of relationship. This relationship is also known as point to point communication. A one-to-one relationship is a table that contains fields that are only used for a certain subset of the records in that table.

One to many

The one-to-many relationship is the common type of relationship in database. This relationship is also known as point to multipoint communication. A one-to-many relationship allows records in the first table to be connected to an arbitrary number of records in a second table. This relationship decrease the size of the database and increases the flexibility.

Many to many

This relationship is more complex than a one to many relationship because in addition to the two tables of data we need another table to join the two tables. This relationship is created by defining the third table.

Step by step solution for create data relationship in LightSwitch

Step 1 : Open Visual Studio LightSwitch->Create new table.


Step 2 : Create a table such as a Contact table.


Step 3 : Go to gender property->Click on choice list->Write the value and display name->Ok.


Step 4 : Now we create the second table. Right click on data sources->Add table.


Step 5 : Create a table such as an EmailAddress table.


Step 6 : Go to emailtype property->Click on choice list->Write value and display name->Ok.


Step 7 : Now we add another table same as in above. This name is PhoneNumber.


Step 8 : Go to phone type property->Click on choice list->Write value and display name->Ok.


Step 9 : Click on relationship in EmailAddress table->Select table name (contact)->Select delete behavior (Cascade delete)->Ok.


Step 10 : Now the result is as in the following image.


Step 11 : Click on relationship in PhoneNumber table->Select table name (contact)->Select delete behavior (Cascade delete)->Ok.


Step 12 : Now the result is as in the following image.


Step 13 : Now the Contact table looks as in the following image.


Step 14 : Now we add a screen. Right click on screens->Add screen.


Step 15 : Select list and details screen->Select screen data (contact)->Mark all checkboxes->Ok.


Step 16 : Run application (Press F5). Click + sign then fill data.