I’ve been demo-ing a project on Azure and happily publishing the project to a couple of different Azure sites during the testing phase. The time came a couple of days ago to publish to a package which I could deploy on the client’s server, which worked fine as well. But then I wanted to update the Azure site again and suddenly got an error – “The following exception was thrown trying to publish: Sequence contains more than one matching element” Some searching got me to this post by Dave Kidder. I found that the settings he mentioned were in the .ls3proj file rather than the .lsproj file (probably a feature of Lightswitch v3) but his fix did get publishing working again. Unfortunately it also broke the authentication on my debugging copy of the project such that Test User could no longer access anything useful. That was probably caused by deleting the .user file but the whole approach seemed a bit brute force so I decided to take a closer look at what actually needed to be changed to fix the error. Comparing the .ls3proj files from before and after publishing to a package, I found only two relevant changes. <RemotePublish>True</RemotePublish> had become <RemotePublish>False</RemotePublish> and <DefaultDatabaseName>My-Database-Name</DefaultDatabaseName> had been added. Changing False back to True and deleting the DefaultDatabaseName property got publishing back on track and the project still works under debugging.
If you’re used to the flexibility of SQL queries, you’ll probably quite quickly find limitations in the way you can query data in Lightswitch. Two common limitations are not being able to change the shape of the data (in other words you can only return complete Customer entities when quering a Customer table rather than just the fields that you want) and not being able to aggregate data using GROUP BY or SUM expressions. The best way around these is to implement a Custom WCF RIA Service and the best guide to doing that is the first half of Eric Erhardt’s article on displaying a chart using aggregated data. This looks complicated before you do it but is actually fairly straightforward once you get going. However even in VS2102, I’d noticed different behaviour in one aspect of this. Some projects do indeed generate the file Server\GeneratedArtifacts\ApplicationData.vb and for these projects the context you need to use in your class library is ApplicationData.Implementation.ApplicationDataObjectContext (ApplicationData is the name of your datasource so your actual name may be different, Eric’s is NorthwindData because he’s using the Northwind sample database). But some projects generate the file Server\GeneratedArtifacts\ApplicationDataObjectContext.vb and for these projects you need to use LightSwitchApplication.Implementation.ApplicationData as the context. I’m still not sure of the difference. I’ve just opened a project of the first type in VS2013 and after allowing the upgrade to happen had a number of errors relating to the file ApplicationData.vb and the context ApplicationData.Implementation.ApplicationDataObjectContext not existing. I presume the second […]
Visual Studio Lightswitch is Microsoft’s rapid development environment for Silverlight and HTML5. A common use case is to develop completely locally using the built in SQL database and then publish code and schema to a remote server and database. This generally works well but if you follow a develop-publish-develop-publish cycle then sometimes your local database schema changes will be rejected by the remote server. When this happens, you’ll typically get one of two unhelpful errors: An exception occurred when deploying the database for the application. Failed to instantiate Microsoft.Data.Schema.Sql.SchemaModel.ExternalPropertyAnnotation because it was not registered. or Incorrect syntax near ‘MULTI_USER These usually mean that there’s a change in your local schema which the remote server can’t apply. A typical scenario would be adding a One-To-Many foreign key relationship to a table with existing data, implicitly creating a required field. The foreign key constraint can’t be applied because there’s no data in the column yet. I had both errors trying to publish a Lightswitch application to Windows Azure. I tracked down and fixed the problem by using the tools available in Visual Studio. Since I’d seen only scattered references and hints to using the tools in this way, I thought I’d post this quick walkthough. This was originally written to update this thread on social.msdn.microsoft.com I’m using Visual Studio Professional 2012 Update 3 configured for Lightswitch development with the current version of SQL Server Data Tools (SSDT) installed. You’ll certainly need reasonably up to date versions of both and if you have […]