This tutorial will demonstrate the creation of a simple LightSwitch application which will be a simple customers application with a single table of customers.
Create a New LightSwitch Project
1. Start up Visual Studio LightSwitch from Start > All Programs > Microsoft Visual Studio 2010 > Microsoft Visual Studio 2010.
2. Select File > New Project and the New Project dialog box will appear.
3. From the Installed Templates listing, select the LightSwitch. (Note that if you are using the full version of Visual Studio Professional with LightSwitch installed you will be shown more templates than just the LightSwitch templates).
4. Select the LightSwitch Application (Visual Basic) template which we will use for this demo and enter a name for the project (in this case I have used lightswitchdemo)
5. Once the application has been created you will be shown an option to either Create a New Table (if the app is being created with an all new database) or Attach to External Database if you need to use LightSwitch as a front-end to an existing database. For this tutorial we will select Create a New Table:
Before we proceed, note the structure of the LightSwitch project from the Solution Explorer in Visual Studio. There are three elements :
- Properties – which is main configuration settings for LightSwitch, such as whether the app will be deployed as as a browser app or a stand-alone desktop app.
- Data Sources – the data tables being used to data storage by the LightSwitch app.
- Screens – the front-end ‘screens’ or pages which the end user will use to interact with the application.
Creating a Data Table in LightSwitch
In this section of the tutorial we will create a table for storing the company’s customer data
1. Click Create new Table from the screen shown above (alternatively you can right-click on Data Sources in the Solution Explorer and select Add Table).
2. Enter the details for each field in the table entry form. In this demo of a customers data tables I have used the fields FirstName, LastName, Email and PhoneNumber. Set the data type for each field, the default type is String, but note the types of EmailAddress and PhoneNumber which have inbuilt validation (as we will see in later tutorials) and should be used whenever possible for these fields. Save the fields by click Control+S or the save icon in the Visual Studio toolbar. For this tutorial I have set all fields to Required, but note that you will often want to uncheck this requirement for some fields to make their input option.
3. Change the table name to Customers by right-clicking on the table (currently named TableItem1) under Data Sources > ApplicationData , and then selecting Rename
Display Customer Data in an Editable Grid
In this final part of the tutorial we will create a simple one screen grid which the user will be able to view, edit and add customers to the LightSwitch application.
1. Right-click on Screens in the Visual Studio Solution Explorer and then select Add Screen… You will then be shown the below screen which lists out the current screen templates available for creating user interfaces in LightSwitch
2. Select Editable Grid Screen from the Listing, enter EditableCustomerGrid as the Screen Name (note that you cannot use spaces for the Screen Name) and select Customers for the Screen Data as shown below and then click OK and the screen should be immediately visible user the Screens folder in the Solution Explorer. Note that for a real-world app we would probably be creating several screens for the app such as a dedicated New Data Screen for inputing data, a Search Screen for performing searches and a Details Screen to display the data.
3. The Properties window should be automatically open, but if not just double-click the EditableCustomerGrid icon in the Solution Explorer. The full listing of screen properties as shown below:
4. Change the Display Name from EditableCustomerGrid to Customers (this is the name of the screen that will be shown to the end-user). Then Save the changes
That’s all that is required to create a very simple LightSwitch app.
Testing and Running the LightSwitch Application From Visual Studio
1. Once the application has been created and saved hit F5 to run it. The application’s main window (see below)is partitioned into three main areas:
Ribbon: This area at the top of the screen gives quick access to common tasks which are performed in the LightSwitch application. The default tasks in the Ribbon are saving the current changes and refreshing the data source.
- Navigation Pane: On the left of the screen the Navigate Pane lists the apps screens.
- Main Pane: The main active working screen. To change screens click another screen from the Navigation View.
2. Using the grid you can enter customer data. Note that on data types such as Email and Phone Number, the validation is built in.
3. Once you have entered the data, click Save on the Ribbon and the data will be saved to the database.
Publish and Deploy a LightSwitch Application From Visual Studio
The deployment process for a LightSwitch application differs depending on the application type which has been selected for the application. The application can be set from by double-clicking Properties in the Solution Explorer and selecting the Application Type tab. There are three application types – Desktop 2 Tier which creates as a simple WPF desktop app, Desktop 3 Tier which creates a WCF app and uses IIS to connect to the data source and Browser Client 3 Tier which creates a browser based Silverlight app:
In this simple demo we are will leave the default, Desktop client 2 tier deployment.
To start the publication process, right-click the main application icon (in this case lightswitchdemo) and select Publish… , the Publish Application Wizard will then be launched:
The first step is to specific the location on the machine to place the application files on the Specify Publishing Preference page. On this page you also need to specify how to create the database, you can either be published directly to an existing database or create a script which can then be executed to create the database manually.
Next, in the Database Configuration specify the connection string for the database (note that the options would be different if you elected to create a database script).
Next, in the Prerequisites you can specify which additional components to install for running the application
Finally, you are will be able to specify any additional settings such as connections to reporting servers.
That’s it! This is a very simple application without many of the features required for actual business apps. In later tutorials we will dive deeper into features of LightSwitch.
Reasons why you must trust ASPHostPortal.com
Every provider will tell you how they treat their support, uptime, expertise, guarantees, etc., are. Take a close look. What they’re really offering you is nothing close to what ASPHostPortal does. You will be treated with respect and provided the courtesy and service you would expect from a world-class web hosting business.
You’ll have highly trained, skilled professional technical support people ready, willing, and wanting to help you 24 hours a day. Your web hosting account servers are monitored from three monitoring points, with two alert points, every minute, 24 hours a day, 7 days a week, 365 days a year. The followings are the list of other added- benefits you can find when hosting with us:
- DELL Hardware
Dell hardware is engineered to keep critical enterprise applications running around the clock with clustered solutions fully tested and certified by Dell and other leading operating system and application providers.
- Recovery Systems
Recovery becomes easy and seamless with our fully managed backup services. We monitor your server to ensure your data is properly backed up and recoverable so when the time comes, you can easily repair or recover your data.
- Control Panel
We provide one of the most comprehensive customer control panels available. Providing maximum control and ease of use, our Control Panel serves as the central management point for your ASPHostPortal account. You’ll use a flexible, powerful hosting control panel that will give you direct control over your web hosting account. Our control panel and systems configuration is fully automated and this means your settings are configured automatically and instantly.
- Excellent Expertise in Technology
The reason we can provide you with a great amount of power, flexibility, and simplicity at such a discounted price is due to incredible efficiencies within our business. We have not just been providing hosting for many clients for years, we have also been researching, developing, and innovating every aspect of our operations, systems, procedures, strategy, management, and teams. Our operations are based on a continual improvement program where we review thousands of systems, operational and management metrics in real-time, to fine-tune every aspect of our operation and activities. We continually train and retrain all people in our teams. We provide all people in our teams with the time, space, and inspiration to research, understand, and explore the Internet in search of greater knowledge. We do this while providing you with the best hosting services for the lowest possible price.
- Data Center
ASPHostPortal modular Tier-3 data center was specifically designed to be a world-class web hosting facility totally dedicated to uncompromised performance and security
- Monitoring Services
From the moment your server is connected to our network it is monitored for connectivity, disk, memory and CPU utilization – as well as hardware failures. Our engineers are alerted to potential issues before they become critical.
ASPHostPortal has architected its network like no other hosting company. Every facet of our network infrastructure scales to gigabit speeds with no single point of failure.
Network security and the security of your server are ASPHostPortal’s top priorities. Our security team is constantly monitoring the entire network for unusual or suspicious behavior so that when it is detected we can address the issue before our network or your server is affected.
- Support Services
Engineers staff our data center 24 hours a day, 7 days a week, 365 days a year to manage the network infrastructure and oversee top-of-the-line servers that host our clients’ critical sites and services.