Hands On with Visual Studio LightSwitch – but what is it for?

Visual Studio LightSwitch, currently in public beta, is Microsoft’s most intriguing development tool for years. It is, I think, widely misunderstood, or not understood; but there is some brilliant work lurking underneath it. That does not mean it will succeed. The difficulty Microsoft is having in positioning it, together with inevitable version one limitations, may mean that it never receives the attention it deserves.

Let’s start with what Microsoft says LightSwitch is all about. Here is a slide from its Beta 2 presentation to the press:

image

Get the idea? This is development for the rest of us, "a simple tool to solve their problems” as another slide puts it.

OK, so it is an application builder, where the focus is on forms over data. That makes me think of Access and Excel, or going beyond Microsoft, FileMaker. This being 2011 though, the emphasis is not so much on single user or even networked Windows apps, but rather on rich internet clients backed by internet-hosted services. With this in mind, LightSwitch builds three-tier applications with database and server tiers hosted on Windows server and IIS, or optionally on Windows Azure, and a client built in Silverlight that runs either out of browser on Windows – in which case it gets features like export to Excel – or in-browser as a web application.

There is a significant issue with this approach. There is no mobile client. Although Windows Phone runs Silverlight, LightSwitch does not create Windows Phone applications; and the only mobile that runs Silverlight is Windows Phone.

LightSwitch apps should run on a Mac with Silverlight installed, though Microsoft never seems to mention this. It is presented as a tool for Windows. On the Mac, desktop applications will not be able to export to Excel since this is a Windows-only capability in Silverlight.

Silverlight MVP Michael Washington has figured out how to make a standard ASP.NET web application that accesses a LightSwitch back end. I think this should have been an option from the beginning.

I digress though. I decided to have a go with LightSwitch to see if I can work out how the supposed target market is likely to get on with it. The project I set myself was a an index of magazine articles; you may recognize some of the names. With LightSwitch you are insulated from the complexities of data connections and can just get on with defining data. Behind the scenes it is SQL Server. I created tables for Articles, Authors and Magazines, where magazines are composed of articles, and each article has an author.

The LightSwitch data designer is brilliant. It has common-sense data types and an easy relationship builder. I created my three tables and set the relationships.

image

Then I created a screen for entering articles. When you add a screen you have to say what kind of screen you want:

image

I chose an Editable Grid Screen for my three tables. LightSwitch is smart about including fields from related tables. So my Articles grid automatically included columns for Author and for Magazine. I did notice that the the author column only showed the firstname of the author – not good. I discovered how to fix it. Go into the Authors table definition, create a new calculated field called FullName, click Edit Method, and write some code:

partial void FullName_Compute(ref string result)
{
    // Set result to the desired field value
   result = this.Firstname + " " + this.Lastname;

}

Then you set FullName as the “Summary” field for the table.

Have we lost our non-developer developer? I don’t think so, this is easier than a formula in Excel once you work out the steps. I was interested to see the result variable in the generated code; echoes of Delphi and Object Pascal.

I did discover though that my app has a usability problem. In LightSwitch, the user interface is generated for you. Each screen becomes a Task in a menu on the left, and double-clicking opens it. The screen layout is also generated for you. My problem: when I tried entering a new article, I had to specify the Author from a drop-down list. If the author did not yet exist, I had to open an Authors editable grid, enter the new author, save it, then go back to the Articles grid to select the new author.

I set myself the task of creating a more user-friendly screen for new articles. It took me a while to figure out how, because the documentation does not seen to cover my requirement, but after some help from LightSwitch experts I arrived at a solution.

First, I created a New Data Screen based on the Article table. Then I clicked Add Data Item and selected a local property of type Author, which I called propAuthor.

image

Next, I added two groups to the screen designer. Screen designs in LightSwitch are not like any screen designs you have seen before. They are a hierarchical list of elements, with properties that affect their appearance. I added two new groups, Group Button and GroupAuthor, and set GroupAuthor to be invisible. Then I dragged fields from propAuthor into the Author group. Then I added two buttons, one called NewAuthor and one called SaveAuthor. Here is the dialog for adding a button:

image

and here is my screen design:

image

So the idea is that when I enter a new article, I can select the author from a drop down list; but if the author does not exist, I click New Author, enter the author details, and click Save. Nicer than having to navigate to a new screen.

In order to complete this I have to write some more code. Here is the code for NewAuthor:

partial void NewAuthor_Execute()
{
     // Write your code here.
     this.propAuthor = new Author();
     this.FindControl("GroupAuthor").IsVisible = true;
}

Note the use of FindControl. I am not sure if there is an easier way, but for some reason the group control does not show up as a property of the screen.

Here is the code for SaveAuthor:

partial void SaveAuthor_Execute()
{
    // Write your code here.
    this.ArticleProperty.Author = propAuthor;
    this.Save();
}

image

This works perfectly. When I click Save Author, the new author is added to the article, and both are saved. Admittedly the screen layout leaves something to be desired; when I have worked out what Weighted Row Height is all about I will try and improve it.

image

Before I finish, I must mention the LightSwitch Publish Wizard, which is clearly the result of a lot of work on Microsoft’s part. First, you choose between a desktop or web application. Next you choose an option for where the services are hosted, which can be local, or on an IIS server, or on Windows Azure.

image

Something I like very much: when you deploy, there is an option to create a new database, but to export the data you have already entered while creating the app. Thoughtful.

image

As you can see from the screens, LightSwitch handles security and access control as well as data management.

What do I think of LightSwitch after this brief exercise? Well, I am impressed by the way it abstracts difficult things. Considered as an easy to use tool for model-driven development, it is excellent.

At the same time, I found it frustrating and sometimes obscure. The local property concept is a critical one if you want to build an application that goes beyond what is generated automatically, but the documentation does not make this clear. I also have not yet found a guide or reference to writing code, which would tell me whether my use of FindControl was sensible or not.

The generated applications are functional rather than beautiful, and the screen layout designer is far from intuitive.

How is the target non-developer developer going to get on with this? I think they will retreat back to the safety of Access or FileMaker in no time. The product this reminds me of more is FoxPro, which was mainly used by professionals.

Making sense of LightSwitch

So what is LightSwitch all about? I think this is a bold effort to create a Visual Basic for Azure, an easy to use tool that would bring multi-tier, cloud-hosted development to a wide group of developers. It could even fit in with the yet-to-be-unveiled app store and Appx application model for Windows 8. But it is the Visual Basic or FoxPro type of developer which Microsoft should be targeting, not professionals in other domains who need to knock together a database app in their spare time.

There are lots of good things here, such as the visual database designer, the Publish Application wizard, and the whole model-driven approach. I suspect though that confused marketing, the Silverlight dependency, and the initial strangeness of the whole package, will combine to make it a hard sell for Microsoft. I would like to be wrong though, as a LightSwitch version 2 which generates HTML 5 instead of Silverlight could be really interesting.

14 thoughts on “Hands On with Visual Studio LightSwitch – but what is it for?”

  1. The core of your criticism is that “Silverlight only runs on Windows Phone.” (that is an exact quote). This assertion is blatently false. Do I need to go into details?

    Care to edit your article?

    1. Ian

      That is in the context of mobile clients; I thought that was clear but just in case I’ve rephrased it.

      Or are you thinking of the Symbian version? I know it exists but it seems pretty much abandoned.

      But what do you think of LightSwitch?

      Tim

  2. I read Tim’s article, and the mobile piece was just one element of the problems.

    Perhaps you might want to do a second pass at reading the article 🙂

  3. @Miguel:
    “…just one element of the problems…” Are you talking about problems with Lightswitch or the article itself?

    @Tim:
    Everything you’ve said seems reasonable to me. I tried v1 of LightSwitch and had perf issues, and haven’t tried v2 yet. I agree that an HTML front-end would seem necessary in the long run, but they should be able to test the usability of the general UI concepts with the Silverlight UI. From your reaction it sounds like the usability/interaction design still needs work.

    You may remember Borland’s “Paradox” database product. The “paradox” was that allegedly Borland had made something powerful that was also easy to use. That’s quite a challenge.

    Vic

  4. Tim,

    Great article.

    I had problems grasping how to approach creating apps with LightSwitch beta 1 and was reminded of a similar issue when I attempted to create a Microsoft Access app in its Cirrus beta 1 version.

    Access’s design mode, which uses Visual Basic-like controls, is much more comprehensible than LightSwitch’s Customize approach.

    In a forthcoming SearchCloudComputing.com column, I’m suggesting the LightSwitch team provide templates similar to those for Access 2010.

    Cheers,

    –rj

  5. Tim, Thanks for the mention.

    While I am not sure how many “Power Excel” users will pick up on this tool, I know that a LOT of “professional developers” will, period.

    In the end you have a SQL Server, WCF, Entity Framework application. You can create your own “Shell” and use Silverlight custom controls to totally recreate the UI.

  6. It’s actually Microsoft Access online but under the Silverlightish banner.. That was the original intent anyway..just quick LOB solutions that most orgs can pump out and sit between Excel Spreadsheet vs Desktop App tiers…

  7. I find it sad that the broad reach of Silverlight is missing to the degree that you feel you need to call out for an HTML5 app.

    HTML5 as a development model isn’t even close in productiveness when you compare it to the quite excellent Silverlight/Moonlight model. C# and XML+XAML is much better choice than Javascript and HTML+CSS, for just about anything than easily reaching devices that Miguel hasn’t targeted.

    I think Lightswitch might be a good application, especially if it could work as a MEF plugin in current applications. So that customers could somehow extend applications themselves that they have bought from vendors.

  8. “So what is LightSwitch all about? I think this is a bold effort to create a Visual Basic for Azure” ?????????

    Out of curiosity why are you comparing Lightswitch with Visual Basic? As a developer that uses VB (among other languages) for over 15 years I find this a trange comparision to be kind.

    First Lighswitch uses VB and C# as possible languegas and furthermore you can use VB for Azure today without lightswitch.

    Plus to that, Lightswitch is composed of multiple frameworks that are both complex and dificult to be grasped by one single developer. We are talking about RIA Services, different datasources including Sharepoint, database and existent RIA Services, Entity Framework, Silverlight on and out of the browser, etc etc etc. Not only LS is more than what you think VB may be, but also VB is more than you thing it is aparently.

    Also… mixing VB and Foxpro? Really?

    1. @LMata

      You are taking me too literally. Think back to the early days of Windows development, it was really hard with Petzold-style C code. Then Visual Basic democratised it with drag-and-drop visual form design and English-like code. I was saying that LightSwitch tries to make the multi-tier development you refer to much easier, in the same way that VB did for Windows development way back when.

      Tim

  9. Ok I can understand your point in *that* context. 🙂 still I would be very careful on mentioning VB and LS on the same sentence because we all know what baggage VB has and we do want to give LS a chance 🙂 Plus you can code in LS with VB or C# so choice of language is also a major plus to it and may put a side some misconceptions.

  10. You write “Have we lost our non-developer developer? I don’t think so, this is easier than a formula in Excel once you work out the steps.”

    After having put in this “easy” code. In fact, I’ll just list the first line of the easy code:
    partial void FullName_Compute(ref string result)

    Is it your honest belief that anyone that mostly uses just excel formulas is going to look at that and say “wow, what an easy way to make an application”? Maybe you do think that, and maybe you’re right, but I think their eyes are going to glaze over from that first line, and go back to recording macros and editing them in excel’s vb editor (if they go that far).

  11. @Mike well, that bit is generated so not really a problem. I agree though, as I noted later in the piece, non-developers will stick to Office.

    Tim

Comments are closed.