As you might know, one of the most important new features in the next version of Visual Studio LightSwitch, currently in beta, is the support for OData.
You can read some post from Beth Massi about this topic, today I'm just showing a different usage.
OData is an open protocol based on WCF Data Services and allows managing data sets through services. If you visit the Ecosystem page of the OData portal, you can find a list of public services from 3rd party producers, including the well-known StackOverflow web site, which offers a very popular forum platform.
Imagine you want to read your favorite threads from StackOverflow inside a LightSwitch application. After creating the project, the first thing you want to do is connecting to an external data source such as OData:
In the next screen of the Wizard we specify the service URL and credentials if required. In this case no credentials are required and Anonymous auth is enough:
In order to be sure that the connection works, click Test Connection and select the entity that will be used for the test:
By clicking Test you will be able to check that everything works. The next step allows selecting entities you want to import into the application. We are talking about entities, this means that LightSwitch is able of representing OData information as the classic entity. So, working with OData is exactly like with any other data source, including business logic, validation, queries, and so on. Let's select posts, tags, and comments:
When you click su Finish, LightSwitch will tell you that it needs to import the User entity as well, since this has a relationship with the Comment one. This demonstrates that LightSwitch perfectly knows how to handle this kinds of situations. Once imported entities and relationships, these will appear in the Table Designer the usual way:
You can replace Date Time with Date to optimize visualization and you can change the summary property from Body to Title. Now imagine you only want to show posts talking about LightSwitch. You can simply create a Query the usual way; Right-click the Posts table in Solution Explorer, then Add Query. The new query is called LightSwitchPosts and we are going to set a couple of filters like in the following figure (tags are lower case):
Now you can simply add a Search Screen pointing to the query:
If you have changed the Summary Property to be Title, in the Properties window you can set this to be Show as Link. I am using here the Cosmopolitan shell which has been released recently. This is how the application will appear when running:
As you can see we have retrieved the list of posts talking about LightSwitch in StackOverflow's forums. You can simply click the hyperlink to show the post details:
OData in LightSwitch opens to infinite new development scenarios, making your applications even more powerful.