Business Connectivity Services in SharePoint 2013 – External Content Type based on OData sources

One of the most powerful new things about the Business Connectivity Services (BCS) component of SharePoint 2013 is the ability to use OData source. In this blog post we’ll go through all the steps to create an External Content Type based on OData source using Visual Studio 2012.

 

Prerequisites:

  1. Microsoft SharePoint 2013 Preview
  2. Microsoft Visual Studio 2012
  3. Microsoft Office Developer Tools for Visual Studio 2012 – Preview
  4. A published OData service (some of Live Services are listed here Live Services).

 

To create the External Content Type, follow these steps:

1. Open Microsoft Visual Studio 2012
2. Click Add a New Project
3. Expand the “Office/SharePoint” node, select “Apps” node and then the “Apps for SharePoint 2013” project type
4. Give your project a name i.e “ODataECTDemo” and click “OK”.

Create BCS 2013 ODataECTDemo project

5. On the next dialog box, enter the name of where you want to deploy your model and the way you want to host this app. I selected “SharePoint-hosted”  in this walkthrough. Click “Finish” button.

Specify the app's settings - BCS 2013

6. In order to add an External Content Type right-click ODataECTDemo project node in the “Solution Explorer” pane, choose “Add” and select Content Types for External Data source” menu item then. You will get a wizard that will help you to specify OData source and create the External Content Type.

Add Content types for External Data source BCS 2013

7. Enter the OData service URL you want to connect to (I will use this one http://services.odata.org/OData/OData.svc/ in this walkthrough) and data source name in the first step of the wizard. Click “Next” button.

Specify OData source

8. Select the data entities for which you want to generate External Content Types. You may select more than one entities. In this demo I selected only entity “Product”. To add an external list automatically make sure that you selected the “Create list instances for the selected data entries (except Service Operations)” checkbox. Click “Finish”.

Select the data entities for which you want to generate External Content Types BCS 2013

9. You can see in the “Solution Explorer” pane that Visual Studio created a new “External Content Types” folder.

new “External Content Types” folder

10. If you expand this folder you can see an External Content Type that related to the entity you selected. In my example this is Product.ect.

External Content Type in graphical mode

11. You may open it either in graphical mode or as xml file if you open it in xml editor.

External Content Type as xml file

12. Also you can see automatically generated List instance xml associated with External Content Type. You should remember list URL that will be used in the further steps. In my case External List relative URL is “Lists/Product”.

List instance associated with External Content Type

13. Now we can build our project. Press F5 to deploy, this will load up the Site Contents page once deployed. Your app will appear in the list of apps on that page.

Site Contents page with deployed app

14. Click the app and you will be redirected to the start page for the app (as defined in the “StartPage” property in AppManifest.xml). You’ll see a pretty simple page which shows your app’s title and your username. Navigate mouse over app name and remember app’s URL that will be used in the next step. In my case app’s URL is http://app-e139481b3ba396.aquarius.sharepoint.local/ODataECTDemo/

Start page for the app

15. In order to open deployed External List you should compose URL this way: app’s URL (described in step 14)+External List relative URL (described in step 12). In my case I have this URL http://app-e139481b3ba396.aquarius.sharepoint.local/ODataECTDemo/Lists/Product. Open this URL and voila, we now done it.

External data provided by OData source is now shown within SharePoint 2013

16. If you want to have an External List on the starting page of the app you should modify the AppManifest.xml file in your project. Open it as xml file in Visual Studio. Find “StartPage” element and replace the value with this one:~appWebUrl+External List relative URL (described in step 12). In my case it looks like <StartPage>~appWebUrl/Lists/Product</StartPage>.

“StartPage” property in AppManifest.xml

17. Now if you press F5 and click the deployed app you will see the External List on the first page.

We hope this walkthrough will be useful for you. If you have any questions feel free to email them to support@lightningtools.com

<Dmitry Kaloshin/>