Microsoft Visual Studio LightSwitch Business Application Development

By Jayaram Krishnaswamy
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Getting Started with Microsoft LightSwitch

About this book

Visual Studio LightSwitch is a new development tool for building business applications for the desktop, the web, and the cloud with ease. You can easily do most of the designing for your application, but for building business applications you need to acquire the right skills. With this book you will gain confidence in working with LightSwitch, and the skills you acquire will greatly help you to develop applications yourself.

This Visual Studio LightSwitch Business Application Development book is dedicated to giving you hands-on experience, when it comes to developing applications on LightSwitch. Everything, right from downloading the software to creating your application to deploying it, is discussed extensively. All this is laid out in an easy to understand and step-by-step format.

You will learn how to set up your database and link to the data whether it is on a local or remote database. Once you know how to work with data, you will then learn to set up screens and use screen templates. Work with entities and LightSwitch specific data types; query and filter data with designer and code. Write simple and complex queries with and without writing code. You will also write custom code using the built-in event handlers.

No business software can function without addressing security issues and Visual Studio LightSwitch has a rock solid, deceptively simple way to handle security and you will learn to do this from scratch with ASP.NET. Once the application is built you will explore the different ways to deploy it.

Publication date:
September 2011


Chapter 1. Getting Started with Microsoft LightSwitch

This chapter begins with explanations as to what makes this software so important and places it in the context of the Visual Studio suite of products. This chapter also aims to help the reader install the required items on the user's computer. It also deals with installing the necessary sample database or databases that will be used together with the LightSwitch applications, as well as other infrastructural details.

Topics to be covered:

  • What is Visual Studio LightSwitch and who is the target audience?

  • Installing Microsoft LightSwitch

  • Installing the databases used in the book

After this chapter, the reader would have a basic understanding of what this software is about, how to install the software, and how to install the necessary database(s) to work with the software.


What is Visual Studio LightSwitch and who is the target audience?

Microsoft Visual Studio LightSwitch (will be called VSLS from here on) is the most recent offering in the Visual Studio suite of products that provides a fast and easy means to create professional-quality line-of-business applications for the three important application genres: the desktop, web, and cloud. However, it is to be noted that in Beta 1, hosting the LightSwitch application on Windows Azure was not supported and in Beta 2, it is supported.

There has been some debate as to the target audience for this product, but from the developments that the product has undergone from Beta 1 to Beta 2, it is easy to see that it should appeal to a larger group than was initially intended. The extension points and the fact that VSLS applications can be deployed to Windows Azure will now appeal to a larger group than was initially envisaged. It should appeal to small businesses that have minimal developer support to bigger departmental applications; to software vendors that would build upon VSLS's core capabilities using its extensibility features; to businesses that may want to migrate their legacy Microsoft Access-based applications to the Cloud. With future enhancements to the product, it may even be possible to move Visual FoxPro applications.

VSLS takes off where Microsoft Access left off. Microsoft's MS Access program became a workhorse for many small businesses and for developing departmental applications in larger businesses, and remained a favorite of these communities for a very long time. This enormous appeal was due to the fact that the program could readily adopt to line-of-business applications with its easy-to-understand object model, support for graphic user interface, support for user management, integration with SQL Servers, support for various export/import tools, and finally its ability to create web-facing applications with Data Access Pages. Yet, Microsoft Access, being file-based, always had security-related issues, as well as a limit on the number of connected users issues. It was not intended for web facing applications, though DAC improved this situation. With the beginning of SharePoint products, Microsoft abandoned its support for DAC.

VSLS may be deemed a much more powerful product due to its capability of creating applications by drawing upon the full power of the .NET Programming technology, its tight integration with SQL Servers including the latest implementation of SQL Server for the Microsoft Azure Cloud platform (the SQL Azure), its most recent framework (SilverLight 4.0) support, and its built-in capability to deploy applications to many different topologies. In fact, this was the first time a single application could be built once and deployed to different topologies. In the past, it was either for Windows or the Web, but not for both. Little did the author suspect that the "out-of-browser" execution of the Silverlight application would have such profound implications (

Microsoft LightSwitch Version 1.0 is expected to be released by the end of 2011, but is guaranteed to be compatible with SilverLight 4.0 (

The line-of-business abstraction is taken to a level where the user needs to be concerned only with data sources and the "screens" that a business is most likely to be concerned with, as the "screens" in the application, represent the patterns common to most of the applications such as search, update, insert, and so on. Most other programs design applications with much more complexity, and much less flexibility and security. VSLS actually leveraged and abstracted the common patterns in business applications. While the Betas provide one such pattern through their default screens; developers and third parties can build custom screens to address their line of business.

VSLS in its release version will be a full-service Integrated Development Environment (IDE), well suited to develop line-of-business applications using Microsoft's latest .NET Framework 4.0 technology.

Unlike the other products in the suite, such as Visual Studio Professional and higher versions, Microsoft LightSwitch is targeted at developers and first-time users with limited exposure to Visual Studio programming models, and the plethora of application types that can be handled with Visual Studio. Microsoft LightSwitch is really for those who want to develop applications quickly and easily, without writing even a line of code. However, if a user needs customization, he or she may yet have to write an additional code, and the original assertion that no code needs to be written maybe bit of a stretch. In order to support custom programming, VSLS does support writing code by providing support to many events that are natural in any application. In addition, one can custom program using the extensive library that can be referenced. Extensions further provide for features built by more experienced developers or third-party vendors. For these and other custom code, Microsoft LightSwitch alone is not enough. It will require at least Visual Studio Professional in Beta2. However in the release version, VSLS may completely cover all aspects of programmability without needing to install higher versions of Visual Studio.

Microsoft LightSwitch can cover the whole spectrum of developers from novices to experts. Already since its release, many such programs have been written by advanced developers as seen in the forums ( and programs developed by third parties (

You can purchase Microsoft LightSwitch 2011 from: There are three different purchase options. A single user can buy it for $199 and save $100 . Beta 1 and Beta 2 versions are available free of cost.


Basic architecture of a VSLS application

What is VSLS and how does it work? Microsoft LightSwitch is model-centric rather than driven by code. The application model is at the heart of a Microsoft LightSwitch application. The application model is built using the application blocks. Entities are built from EntityTypes and queries derive from entities. Screens consist of controls. The built-in designers use these blocks to create the application; picking entities and binding them with the desired screens. The run time gets this model moving by loading the application, retrieving the data, overseeing and running the logic that binds the screens with data, and a host of other activities.

The VSLS designers

It is the built-in designers that give the flexibility to the application developers in choosing data, and tailoring their displays and user interface. The designers work with the blocks described in this section.

As mentioned earlier, VSLS is specifically meant for line-of-business applications and EntityType is its basic unit. For example, as shown in the next screenshot, Customer described by its various constituents, is an example of Entity Type, and so is Order. The Customer has a Key Property as well in relation to the other entity Order; it has a Navigational Property shown by the line joining the two. Additionally, although not shown explicitly in the screenshot, there is also a Computed Property that you see as one of its menu items. It is not mandatory for an entity to have navigational or computed properties. The data source NorthwindData is a container of these entities. The entity designer is where you define a new entity or bring one by attaching it to the data from an external source.

The query designer shown in the next screenshot is where you design a query after choosing an entity on which it is based. A query based on another query is also allowed. A query has the same data as in an entity, but only some selected version of it. That is, it has the data that is filtered and sorted based on some criteria that you can set in the designer.

The Screen designer shown in the next screenshot is where a screen is designed. The IDE binds the data to the screen when you bind the entity to the screen to expose the entity to a user. These screens are pre-built to address common business scenarios, but with extensions it will be possible to build custom screens. However, one can start with an unbound screen (shown in the next screenshot) and bring in entity data or query data to the screen using hooks (Add Data Item…) in the Screen designer.

If you become conversant with using these designers, then you will be able to build applications effortlessly, as the screens, the queries, and the entities are tightly bound by the IDE.

After designing the application in the IDE, it is the run time that executes the program to achieve the design objectives and display results to the user. The run time is based on many other Microsoft technologies, such as Model View ViewModel (MVVM), SilverLight, WCF Data Services, and so on, that utilize the best practices to provide a secure and extensible application which can be hosted on both the desktop and Web; a hitherto unavailable feat in a single application. A user can indeed work with the IDE to create applications without a full understanding of the behind-the-scene workings of these sophisticated technologies. However, to create something that is not built-in, it will be necessary to have an understanding of the above technologies to some extent.

Applications can be written without a line of code just by using the built-in features. However, run time can also draw upon the Application Programming Interfaces (APIs) to write code against events that an application would raise, such as an entity getting updated, a screen element getting displayed, or a validation being checked, and so on. The extensibility points available in the IDE provides for more advanced customization.

In the next section, the preliminary tasks necessary for working through the rest of the book will be described.


Installing Microsoft LightSwitch

Microsoft LightSwitch program vs_vslsweb.exe (3.3MB, version Beta 2, Date Published: 3/7/2011) may be downloaded from the location: and saved to a location of your choice. The saved file can be used to install the program later.

The following are the system requirements:

  • Supported Operating Systems: Windows 7; Windows Server 2003 R2 (32-Bit x86) or above, Windows Server 2003 R2 x64 editions, Windows Server 2003 Service Pack 1 or above, Windows Server 2008, Windows Vista, Windows XP Service Pack 2 or above.

  • Supported Architectures:

    • x86

    • x64 (Windows 32 on Windows 64 bit)

The following are the hardware requirements:

  • A computer with a 1.6GHz or faster processor

  • 1024MB RAM (1.5GB if running on a virtual machine)

  • 3GB of available hard-disk space

  • 5400 RPM hard drive

  • DirectX 9 capable video card running at 1024 x 768 or higher-resolution display

This book was developed using the (x32) Windows 7 Ultimate OS on an ASPIRE notebook computer.

Describing the installation of the product will be limited to Windows 7 and Windows XP, although it can be installed on many more operating systems both x32 and x64. As some of the would-be users (non-programmer, hobbyist, junior developer, and so on) will be using either Windows XP or Windows 7, installing on these OSs will be described in the following sections.

Installing on Windows 7

Installation on Windows 7 and on Windows XP is carried out similarly except that there could be some individual differences as well as problems that some may encounter.

  1. Download the Microsoft VSLS from the link mentioned earlier: (


    You can either purchase a single individual user's or developer's copy or download a trial version from:

  2. Double-click on the executable vs_vslsweb.exe in the download location shown in the next screenshot:

  3. This displays the Welcome to Setup page of Microsoft Visual Studio LightSwitch Beta Edition Setup window, as shown in the next screenshot:

    Read the EULA before you click on Install Now.

  4. Click on Install Now.

    The installation starts downloading the needed files that may vary depending on the computer on which they are installed. The VSLS server software is downloaded as shown in the next screenshot:

    This is followed by the VSLS Beta Edition program as shown in the next screenshot:

    These are the only components that are downloaded assuming you have Silverlight 4.0 on your computer and the other components ( If Silverlight 4.0 is not installed, the above installation will install Silverlight 4.0.


    If you have an older build of Silverlight 4.0 Visual Studio LightSwitch, install a newer version of Silverlight - 4.0.50630.0. This could be an issue with some Silverlight projects that you did before. It is recommended to download the latest public build of Silverlight 4: 4.0.50917.0. You can find it here: Silverlight Tools 4 ( and Silverlight Runtime:

  5. Click on Close after the download is complete.

    This starts the installation and at its conclusion you will get the window shown in the next screenshot. Now you are ready to start using VSLS. This whole process took less than half an hour on the computer used.

Installation problems and remedies

It may not be possible to describe all problems and their remedies, but some of them encountered while developing the material for this book will be described. The VSLS team has come up with a comprehensive list of the components that should be present for successful installation: problems and fixes ( You may experience varying degrees of difficulty, especially if you have the beta and CTP versions of some Microsoft programs. In one of the earlier installations on this computer, when one of the components was absent, installation did not succeed till the required component was installed. For details, review the link:

In case you are unable to install for some reason, you should take a look at the installation log files: dd_VSMsiLLogXXXX.txt or dd_error_vs_vslscore_100.txt to identify where your installation might have gone wrong. To find this and related files, go to the Logs sub-folder in the installation folder: \Microsoft Visual Studio LightSwitch Beta Edition – ENU\Logs. Some of these files could run to a couple of thousand pages. If there are no errors, the error file will be empty.

Installing on Windows XP

While this section describes the installation of Beta 2 on Windows XP, the information will still be useful for installing Microsoft LightSwitch 2011. You will still need Windows (x32) SP with SP3. Review the link at: for more information.

Installing on Windows XP is no different from installing on Windows 7, except that you need to note the following, and in case you find these indicated programs on your computer, do what is required, as indicated.


Please note that:

At a minimum, you should have Windows XP with (Service Pack) SP 2.

On the computer used for this book, SP3 was installed.

Beta of WCF RIA Services, if present, should be removed.

Beta 2 of MS .NET Framework 4 client, if present, should be removed.

Also note that before you remove Beta 2 of MS .NET Framework 4 client, you should remove .NET framework 4 extended Beta 2, if you have it. These betas were removed from the author's computer before installing LightSwitch.

It is preferable to have SQL Server 2008 Express (or higher up to SQL Server 2008 R2 Enterprise), as well as the recently released free edition, the SQL Server Express 2008 R2 ( on the computer, as it is used by VSLS applications. According to the answer found in the forum (, VSLS installation should install SQL Server 2008 Express, if it is not already present. It is assumed you have the necessary .NET Framework (.NET 3.5) to install SQL Server 2008 Express 2008. On the author's computer, SQL Server 2008 Express was already present. In addition, Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86) Enterprise evaluation edition was also present.

In case SQL Server is not installed for any reason, the following link describes the three flavors of SQL Express that you can install on your computer and the links to their download sites:

All you need to do is to double-click on the vs_vslsweb.exe file to start the download and installation process.

Follow the installation wizard instructions and the wizard steps may not be the same as in the case of Windows 7, as the installed programs on Windows XP SP 3 may be different from those on Windows 7. For example, the installation displayed the next screenshot when the download and installation process started:

This download will continue until all the following items are downloaded and installed on the computer:

  • VC 9 and VC10 runtime (x86 or x64)

  • MS .NET F 4.0

  • MS .Net Framework 4.0 Multi-targeting pack

  • SQL Server 2008 R2 Management Objects

  • MS Help Viewer 1.0

  • TFS Object Model (x86)

  • MSWeb deployment tool (x86)

  • Silverlight 4 SDK

  • WCF RIA Services

  • Microsoft Visual Studio LightSwitch Beta Server

  • Microsoft Visual Studio LightSwitch Beta Edition

The installer verifies the already-installed components and installs the programs that are not present on the computer. For a comprehensive list of programs installed, follow this link: It has a list of most of the installation-related troubleshooting information as well.

After downloading and installing the files, Visual Studio LightSwitch Beta 2 will be installed without any problem, although the whole process takes nearly two hours (with an average download speed of 185 kbps on the Wi-Fi connection, compared to under half an hour on Windows 7).


Installing the databases used in the book

As the book will be using Northwind and Adventure Works databases whenever a database on the SQL Server 2008 Express is used, these databases will be required to work with the book. The following section describes where to obtain the sample databases, as well as bringing them to the SQL Server 2008 Express installed on the computer. By default, the server installation does not contain sample databases.

Downloading the samples

Download sites depend on how long the databases have been in use, as the earlier databases were smaller and the more recent ones are larger.

Installing the databases on SQL Express 2008

The installation of databases on SQL Server 2008 requires attaching the database MDF and LDF files to the server. This process is described in the following blog:, where an Adventure Works database is installed on an instance of SQL Server 2008 R2.

However, with the sample files download from, which provides a ZIP file, the process is even simpler if you follow these indicated steps:

  1. Download SQL2000.Sample.Databases.(Northwind, pubs).zip, a 1.2MB file from:


    The file contains both the Northwind and the pubs database-related files. You will find both the MDF and LDF files for these databases, as well as the install scripts instnwnd.sql and instpubs.sql files. Make sure you read the ReadME_SQL2000SampleDbScripts.html file for further guidance.

  2. Extract the files from the ZIP to a location of your choice.

  3. Connect to the SQL Server Express in the Microsoft SQL Server Management Studio.

  4. Right-click on the databases node and choose Create a new database.

  5. Create a new database Northwind in SQL Server 2008 Express.

  6. Expand the Database node and right-click on the master database node and choose New Query.

  7. In the Management Studio's menu, click on File | Open | File...; browse and locate the instnwnd.sql script file mentioned earlier.

  8. The installation script gets copied to the query window.

  9. Do a syntax check and execute the query by clicking on the Menu icon.

  10. The script is executed very quickly and you have the Northwind database in SQL Server 2008 Express.

  11. After the query is run, you must be able to find the Northwind database in your SQL Server 2008 Express as shown:

In a similar manner or using the method suggested earlier in the author's blog, the Adventure Works database can also be installed on the server.



The chapter describes some of the basic architectural features of VSLS for designing VSLS applications. Features that differentiate this product from other programs are also described. After describing the hardware and software requirements for installing VSLS, the download and install process is described for both Windows 7 and Windows XP. Downloading and installing the sample databases, which are used with this software, is also described.



Here are some of the resources that will help in your understanding of VSLS Applications:

About the Author

  • Jayaram Krishnaswamy

    Jayaram Krishnaswamy studied at the Indian Institute of Science in Bangalore India and Madras University in India and taught at the Indian Institute of Technology in Madras. He went to Japan on a Japanese Ministry of Education Research scholarship to complete his PhD in Electrical Engineering from Nagoya University. He was a Post-Doctoral Fellow at Sydney University in Australia; a Government of India Senior Scientific Officer at the Indian Institute of Science in Bangalore and Indian Institute of Technology at Kanpur; a Visiting Scientist at the Eindhoven Institute of Technology in the Netherlands; a visiting Professor of Physics at the Federal University in Brazil; an Associate Research Scientist at a government laboratory in São Jose dos Campos in São Paulo, Brazil; a visiting scientist at the National Research Council in Ottawa, Canada before coming to USA in 1985. He has also taught and worked at the Colorado State University in Fort Collins and North Carolina State University in Raleigh, North Carolina. He worked with Northrop Grumman Corporation on a number of projects related to high energy electron accelerators and Free Electron Lasers. These projects were undertaken at the Brookhaven National Laboratory in Long Island and in the Physics Department at Princeton University. He has over 80 publications in refereed and non-refereed publications and 8 issued patents. He is fluent in Japanese and Portuguese and lives in Honolulu, Hawaii, USA.

    He has been working in IT-related fields since 1997. He was once a Microsoft Certified Trainer in Networking and a Siebel Certified developer. He has worked with several IT related companies, such as the Butler International in their Siebel practice, with several IBM sub-contractors and smaller companies. Presently he is active in writing technical articles in the IT field to many online sites such as,,,,,, Egghead Café,, Packt Article Network,,, and many others. Between 2006 and 2010 he wrote more than 400 articles mostly related to database and web related technologies covering Microsoft, Oracle, Sybase, ColdFusion, Sun, and other vendor products.

    He has written four books all published by Packt related to Microsoft Database and Application Development: SQL Server Integration Services Using Visual Studio 2005, Learning SQL Server Reporting Services 2008, Microsoft SQL Azure; Enterprise Application Development, and Microsoft Visual Studio Lightswitch Business Application Development. He regularly writes for his four blogs on Blogger;,,, and He received the 2011 Microsoft Community Contributor award.

    Contact Jayaram Krishnaswamy

    Browse publications by this author
Book Title
Unlock this book and the full library for FREE
Start free trial