Relationship Building in LightSwitch 2012

In my previous article I described how to establish a relationship among multiple tables using LightSwitch in Visual Studio 2012. (See: http://www.c-sharpcorner.com/uploadfile/18ddf7/creating-relationship-between-multiple-tables-in-lightswitch/).

I am now proceeding from that article.


Here we will see how to develop a many-to-many relationship in LightSwitch 2012.

Note: A many-to-many relationship is not supported in LightSwitch.

Here I am providing an easy solution for creating ammany-to-many relationship in Lightswitch 2012.

Procedure for showing a many-to-many relationship in LightSwitch 2012.

Step 1

To add a small amount of data we need to develop the screens. In the Solution Explorer, right-click on Screens and choose "Add Screens".

add src.jpg

Step 2

Choose the "Editable DataGrid Screen" from the Screen Template. Under Screen Information we provide the Screen Name and select "Customer" from the Screen Data and then click "OK".

add customer src.jpg

Do the same for the Item table, in other words once again choose the "Editable DataGrid Screen" from the Screen Template. Under Screen Information we provide the Screen Name and select "Item" from the Screen Data and then click "OK".

add item src.jpg

Step 3

Add another Screen. Now this time choose "List and Details Screen" from the Screen Template. Under Screen Information we provide the Screen Name and select "Customer" from the Screen Data. Mark the Customer CustomerItemMaps checkbox as checked and then click "OK".

list and detail src customer.jpg

Add another List and Details Screen. This time select "Item" from the Screen Data and mark the Item CustomerItemMaps checkbox as checked and click "OK".

list and detail src item.jpg

Step 4

Press F5 to run the application. You will see the Editable Customer Grid Screen open. Enter some data and click on the "Save" Button.

customer data in output.jpg

If sometimes you are unable to get the Editable Customer Grid Screen then select it from the Tasks Menu.

tasks.jpg

Step 5

Similarly, select the Editable Item Grid from the Tasks Menu and enter some data and save it.

task item list.jpg

item as output.jpg

Step 6

Now we can test the relationship. Choose the Customer List Detail from the Tasks Menu.

customer list task.jpg

The list of customers along with the item appears.

customer list output.jpg

We can easily relate items to the customers. For example select the "Satya" from the Customer and from the drop down list of Items choose any item.

customer item table.jpg

Step 7

Now select the Item List detail from the Tasks Menu and we can now also relate customer to items by selecting the specific customer.

customer item table 1.jpg

In this way we can establish the relationship between tables.