Issues upgrading a WCF RIA Service project to VS2013

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 type is now the default behaviour in VS2013. The fix is simply to relink to the correct file and then change the context names in your library.

In your WCF Project (NorthwindTraders.Reporting in Eric’s example), right click ApplicationData.vb and select Remove. Then right click the project name, select Add -> Existing Item, navigate to Server\GeneratedArtifacts in the main project, select ApplicationDataObjectContext.vb, change “Add” to “Add As Link” and click to add a link. Now open your class library (NorthwindTradersReportData.vb in Eric’s example) and change the three occurrences of ApplicationData.Implementation.ApplicationDataObjectContext to LightSwitchApplication.Implementation.ApplicationData. The errors should now have resolved.