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:
- Microsoft SharePoint 2013 Preview
- Microsoft Visual Studio 2012
- Microsoft Office Developer Tools for Visual Studio 2012 – Preview
- 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”.
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.
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.
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.
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”.
9. You can see in the “Solution Explorer” pane that Visual Studio created a 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.
11. You may open it either in graphical mode or as xml file if you open it in xml editor.
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”.
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.
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/
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.
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>.
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/>