Building Mobile, Touch-Oriented Business Apps with the HTML Client in Visual Studio LightSwitch 2012
Preparing the Data
The sample application will be a simplified environment for managing customers and orders per customer. The first step is creating the appropriate tables. The first table you create is called Customer; Figure 3 shows its definition.
Figure 3 Creating the Customer table.
The second table to define is Order (see Figure 4). It provides a simplified representation for an order managed by a company.
Figure 4 Creating the Order table.
Data validation on the server still works in the familiar way, so you can enforce data validation by handling the Validate method for each property. For instance, you can validate the DeliveryDate property as follows:
Private Sub DeliveryDate_Validate(results As EntityValidationResultsBuilder) ' ensure users enter valid dates If DeliveryDate < OrderDate Then results.AddPropertyError("The delivery date must be greater than the order date") End If End Sub
This is very important, because the HTML client can raise validation errors in the user interface, based on the server-side validation.
The next step is establishing a one-to-many relationship between Customer and Order. Using the Relationship button in the Table Designer, add a new relationship in which Customer is the "one" part and Order is the "many" part, as shown in Figure 5.
Figure 5 Establishing a relationship between tables.
Now that the data structure is ready, it's time to generate the user interface.