Building a basic Lightswitch application


Microsoft LightSwitch is an IDE that can build business applications without writing any code. The screens are generated from the data that is used. In this small article I will walk you through creating a simple application.


First some information about LightSwitch. LS builds 3-tier applications, the interface is build using Microsoft Silverlight in combination with WCF RIA services and Entity Framework, the default datastore for LS is SQL server express. LS also supports data from SQL Azure, MS Sharepoint and SQL server. As for language, support for Visual Basic and C# is build in. LS is currently in its second beta version, a full release is scheduled for end of 2011.


I’m going to create an application that lists superheroes, their owner, powers and city of operations. I will not use an existing database, so LS will use a newly created SQL server express DB.
My development machine is running Windows 7 professional 64-bit with Visual Studio 2010 enterprise and sql server express 2008 R2.


Naturally we kick this off by starting a new project in VS2010 so go to File > New > Project, select Lightswitch as projecttype and select a C# Lightswitch project. Give it a name and click OK.

project selection(Click to enlarge)

After the project finishes loading we find ourselves in the very minimalistic interface that is Microsoft Lightswitch, we only have 2 options on the start screen, Create new table or Attach to external data source. These options speak for themselves, create new table creates a new sql server express database for this project, attach to external data source allows you to connect to a sql database, a sharepoint  database or a sql azure database. We will create a new database for our superhero collection, so select Create new table.

initial screen(click to enlarge)


This opens up a graphical table design, start by naming the table and add columns like in the screenshot. In the properties of the ID column deselect the Display by default checkbox, this makes sure that the ID field isn’t shown in the application.

initial screen
(click to enlarge)


Create 2 more tables, City and Owner, make them like the screenshots below.

initial screen(click to enlarge)

initial screen(click to enlarge)

Next Page -->

This is an imported post. It was imported from my old blog using an automated tool and may contain formatting errors and/or broken images.