Share via


Defining Relationships

This lesson shows how to define a relationship between data entities in a LightSwitch application.

Define a Relationship

Many applications use information from more than one source of data. For example, an application in which users enter retail orders might pull product information directly from the manufacturer’s database. By using LightSwitch, you can define a relationship between entities in different data sources as long as data in a field in one source relates to data in a field in the other source.

To define a relationship

  1. In Solution Explorer, open Contacts.

  2. On the Data Designer toolbar, choose Relationship.

    The Add New Relationship dialog box opens.

  3. In the Name: row in the To column, choose Customer.

  4. In the Multiplicity row, choose One in the From column and Zero or one in the To column.

  5. In the Select the fields on ‘Contact’ that are shared with ‘Customer’. section, in the Contact (Foreign) column, choose ContactPhone (PhoneNumber).

  6. In the Customer (Primary) column, choose Phone (PhoneNumber), and then choose the OK button.

    A relationship between Order_Detail and Product

    You have now defined a relationship between the Contacts entity and the Customers entity. If a value in the Phone field in the Customers table matches a value in the ContactPhone field in the Contacts table, information about the customer can appear.

Closer Look

This lesson showed how to define a relationship between entities from different data sources. You may have noticed that the relationship is denoted in the designer by a dotted line. The dotted line signifies that the relationship is between different data sources. Relationships between entities in the same data source are denoted by a solid line.

You can also define relationships between disparate types of data sources. For example, you can define a relationship between a data entity that you create in LightSwitch and a SharePoint list.

Next Steps

This lesson is the last one in the Data section of the guided tour. The next set of lessons, Creating Screens, teaches how to create screens in which users can display and edit data.

See Also

Other Resources

Working with Data in LightSwitch (Guided Tour)

How to: Create a Relationship Between Entities