Visual Studio 2013 Preview – What’s New With LightSwitch

At the start of the Microsoft Build 2013 Conference, a preview release of Visual Studio 2013 has been made available.

This morning I was finally able to get it installed properly… there are a number of exciting changes. In this post, I’ll just summarize some of the changes affecting LightSwitch users:

  • In the General Properties for the LightSwitch solution, there is a new “SQL Database Project” drop-down, which @janvanderhaegen says is for providing “seed data” to your database.
  • The server project now defaults to .NET Framework 4.5
  • No more separate Logical/File views… instead there are folders for “Screens” under the client subproject and “Data Sources” under the server subproject.
  • Each screen has its own lsml file. Each entity has its own lsml file. This is a huge boon for multiple developer collaboration, as it greatly reduces the headaches of merging changes.
  • In the HTML Client, the javascript code behind for a screen now includes “lsml” in the name. So if you name a screen “BrowseCustomers”, the screen file itself will be “BrowseCustomers.lsml” and the corresponding javascript code-behind file will be “BrowseCustomers.lsml.js”
  • You can have multiple Lightswitch Entity and Screen designer windows open at the same time.
  • In the HTML Client, there are now refresh() methods for the VisualCollection and the EntityDetails objects.


That last bit bears some explanation. Previously, if you needed to force the HTML client to requery the database to get the latest version of a given entity (or entity collection if you were dealing with List or TileList controls), there was no good built-in method for handling it. You had to resort to writing you own helper functions to invalidate the client-side cache that Lightswitch was using (the _loadedEntities array, and often the _linkSets).

And if you wanted only to reload a single entity, but that entity had NavigationProperties relating it to other entities, you had to not only delete the corresponding entry from _loadedEntities, but also had to traverse the _linkSets arrays recursively to invalidate related entities (and entities related to those entities… etc), otherwise you were bound to run into problems.

No more! Now with VS 2013 Lightswitch, you have refresh() methods for the VisualCollection and for EntityDetails.

Suppose you have a BrowseCustomers screen with a Customers List control. You can create a “Refresh” button with code like this:

myapp.BrowseCustomers.Refresh_execute = function (screen) {
    screen.getCustomers().then(function (customers) {
        customers.refresh();
    });
};

And suppose you have a ViewCustomer screen displaying a single customer. You can create a “Refresh” button there with code like this:

myapp.ViewCustomer.Refresh_execute = function (screen) {
    screen.Customer.details.refresh();
};

Note that, as pointed out in the intellisense description for the methods, they only update the entity if it doesn’t have unsaved changes (which is what you generally want…. if you want to reload an entity which has unsaved changes, just discardChanges first)

The EntityDetails function refresh(navigationPropertyNames):

Updates the entity with values from the data source if the entity
is not changed.

<param name="navigationPropertyNames" type="Array" optional="true">
An array of names of navigation properties to be included. An empty
array means no properties will be included. If not specified, all
reference properties are included.
</param>
<returns type="WinJS.Promise">
A promise that is fulfilled when the update is completed.
</returns>

The VisualColection function refresh():

Asynchronously loads the first page of items into this collection and
returns a promise that will be fulfilled when the first page is loaded.
Existing results will be refreshed on the first page and subsequent
pages unless load() is called again.
<returns type="WinJS.Promise">
A promise that is fulfilled when the first page is loaded.
</returns>

We should be hearing much more from Joe Binder’s Lightswitch talk at Build today (27 June 2013) as well as the Lightswitch Team blog.

In the meantime, be sure to check out Xpert360’s blog for more info on many of these changes.

Update:
Announcing LightSwitch in Visual Studio 2013 Preview – Official Microsoft LightSwitch blog

2 thoughts on “Visual Studio 2013 Preview – What’s New With LightSwitch

  1. Thanks for the article! Do you happen to have an example of how you use _loadedEntities to do a refresh() today in the HTML Client?

    Thanks
    Jay Turpin
    Intel Corp

    • Hi Jay,

      Unfortunately the only solid implementation (read “properly traverses the linkSet tree to invalidate linked entities”) I have is part of a closed source project, so I’m not at liberty to share it.

      However, I’ve been experimenting with using msls-2.0.0.js (the Lightswitch HTML client javascript library from the Visual Studio 2013 Preview) in a Visual Studio 2012 Lightswitch project… it looks promising.

      That way, you may be able to take advantage of the new client side code on existing projects without using Visual Studio 2013.

      Note that the Visual Studio 2013 Preview has a “go live” license (see http://visualstudiomagazine.com/articles/2013/06/26/microsoft-releases-preview-of-vs-2013.aspx )

Comments are closed.