Elucidate LightSwitch Beginning in Visual Studio 2013 Part 1

Welcome to Part 1 of the Elucidate LightSwitch article series.
In this article we will see the  walkthrough of LightSwitch. We will have a look at one of the most important building blocks of a LightSwitch application, the table, that is a way of organizing data in columns and rows. We will see how to create and work with tables in LightSwitch.
Tables In LightSwitch
LightSwitch applications are data-centric applications that provide user interfaces for performing CRUD operations LightSwitch simplifies the development of these applications by using screens and tables, since LightSwitch can work with other external data sources that do not necessarily have to come from a database. 
Since my articles are for absolute beginners let's start from scratch.
Let's get started with a practical example of creating an entity for creating an application that manages contacts, like an address book. For that we need to create an entity that stores the contact data.
  • Step 1: Create a new project by opening Visual Studio 2013 then select "File" -> "New" -> "Project..." then select "LightSwitch Html Application" then name it "ContactBuilder" and click "OK" as shown below.
       We can see that the LightSwitch home page will ask us if we want to create a new table or attach to an external data source.

  • Step 2: Now click on "Create new table" that will redirect us to the data designer. Now we can start describing the contact entity as shown below.

Once we have done that we will see “Contacts” in the Solution Explorer under the ApplicationData node in the Data Sources folder. ApplicationData represents the intrinsic (internal) database that LightSwitch creates for us. Contacts refers to the table in the database that stores all the contact rows (or records).

Now let's start defining properties on our entity that correlates to the columns (or fields) on the table. Note at this point the Contact entity has a property called "id" that we cannot modify.This is an in internal field that represent a unique key to the specific row of data. When we model tables in a database, each row in the table must have a unique key so that a specific row can be located in the table.This id is called a primary key as indicated by the picture of the key on the left of the property name. It is always required, unique and is stored as an integer. That clearly indicates that LightSwitch handles managing primary keys automatically for us.

Notice here that we have selected types that closely match the type of data we want to store. For Phone and Email we have slected the "Phone Number" and "Email Address" types that are built in validation and editors on the screens. The data is stored in the underlying table as strings, but is formatted and validated on the screen automatically for us.

In this article we saw how to use tables in LightSwitch. In future articles we will proceed with this article series.

Similar Articles