{"id":1504,"date":"2013-08-09T16:21:47","date_gmt":"2013-08-09T15:21:47","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1504"},"modified":"2013-08-09T16:21:47","modified_gmt":"2013-08-09T15:21:47","slug":"external-content-type-walkthrough","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2013\/08\/09\/external-content-type-walkthrough\/","title":{"rendered":"External Content Type Walkthrough"},"content":{"rendered":"<p>Looking to design your own external content type and deploy it as part of a SharePoint solution? Read on for a walkthrough on how to create one.<\/p>\n<p>First up, the steps are the same for SharePoint 2010 and 2013 and have been carried out using Visual Studio 2012. Visual Studio 2010 will also work.<\/p>\n<p>Before I start the walkthrough, I&#8217;ll summarise the goal of this post:<\/p>\n<p>We have a very simple database that contains a couple of tables &#8211; Customer and Order.  An external content type will be created and via a view on the database, will return a list of customers and their orders.  The external content type will only allow read access to this information.<\/p>\n<p><strong>Assumptions<\/strong>:<\/p>\n<ul>\n<li>There is a Business Data Connectivity service up and running on the SharePoint farm for the External Content Type (ECT) to be deployed to.<\/li>\n<li>The user deploying the solutions containing the ECT, in this case the user running Visual Studio, has adequate permissions to create it in the application service.<\/li>\n<li>This is just a demonstration, so there will be a distinct lack of logging, error handling and bad practices such as storing database credentials in plain text within the code, try to ignore this \ud83d\ude42<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<p>OK, let&#8217;s get going.<\/p>\n<p>Open Visual Studio and either load your existing SharePoint project or create a new one.<\/p>\n<p>The first thing we need to do is create the Business Data Connectivity Model, so go ahead and add one to your project.<\/p>\n<div id=\"attachment_1516\" style=\"width: 965px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewBDCModel.png\"><img aria-describedby=\"caption-attachment-1516\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewBDCModel.png\" alt=\"Add new BDC Model\" width=\"955\" height=\"660\" class=\"size-full wp-image-1516\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewBDCModel.png 955w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewBDCModel-300x207.png 300w\" sizes=\"(max-width: 955px) 100vw, 955px\" \/><\/a><p id=\"caption-attachment-1516\" class=\"wp-caption-text\">Add new BDC Model<\/p><\/div>\n<p>Which will show something very similar to the following screenshot:<br \/>\n<div id=\"attachment_1517\" style=\"width: 429px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/InitialBDCModelDiagram.png\"><img aria-describedby=\"caption-attachment-1517\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/InitialBDCModelDiagram.png\" alt=\"Initial BDC Model Diagram\" width=\"419\" height=\"334\" class=\"size-full wp-image-1517\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/InitialBDCModelDiagram.png 419w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/InitialBDCModelDiagram-300x239.png 300w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/a><p id=\"caption-attachment-1517\" class=\"wp-caption-text\">Initial BDC Model Diagram<\/p><\/div><\/p>\n<p>It easier to start with a clean slate, so delete the existing entity from the diagram.<\/p>\n<div id=\"attachment_1519\" style=\"width: 357px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeleteEntity1.png\"><img aria-describedby=\"caption-attachment-1519\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeleteEntity1.png\" alt=\"Delete Entity1\" width=\"347\" height=\"236\" class=\"size-full wp-image-1519\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeleteEntity1.png 347w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeleteEntity1-300x204.png 300w\" sizes=\"(max-width: 347px) 100vw, 347px\" \/><\/a><p id=\"caption-attachment-1519\" class=\"wp-caption-text\">Delete Entity1<\/p><\/div>\n<p>In the Solution Explorer pane, delete the Entity1 and Entity1Service classes.<\/p>\n<div id=\"attachment_1522\" style=\"width: 269px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeleteEntity1Classes.png\"><img aria-describedby=\"caption-attachment-1522\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeleteEntity1Classes.png\" alt=\"Delete Entity1 Classes\" width=\"259\" height=\"333\" class=\"size-full wp-image-1522\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeleteEntity1Classes.png 259w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeleteEntity1Classes-233x300.png 233w\" sizes=\"(max-width: 259px) 100vw, 259px\" \/><\/a><p id=\"caption-attachment-1522\" class=\"wp-caption-text\">Delete Entity1 Classes<\/p><\/div>\n<p>Back in the Model, add a new entity.<\/p>\n<div id=\"attachment_1523\" style=\"width: 815px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewEntity.png\"><img aria-describedby=\"caption-attachment-1523\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewEntity.png\" alt=\"Add New Entity\" width=\"805\" height=\"338\" class=\"size-full wp-image-1523\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewEntity.png 805w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewEntity-300x125.png 300w\" sizes=\"(max-width: 805px) 100vw, 805px\" \/><\/a><p id=\"caption-attachment-1523\" class=\"wp-caption-text\">Add New Entity<\/p><\/div>\n<p>Next, rename it to CustomerOrders.<\/p>\n<div id=\"attachment_1524\" style=\"width: 713px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/RenameNewEntity.png\"><img aria-describedby=\"caption-attachment-1524\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/RenameNewEntity.png\" alt=\"Rename New Entity\" width=\"703\" height=\"335\" class=\"size-full wp-image-1524\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/RenameNewEntity.png 703w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/RenameNewEntity-300x142.png 300w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><\/a><p id=\"caption-attachment-1524\" class=\"wp-caption-text\">Rename New Entity<\/p><\/div>\n<p>Note the new service class that was automatically created for you.<\/p>\n<div id=\"attachment_1525\" style=\"width: 297px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/NewCustomerOrderServiceClass.png\"><img aria-describedby=\"caption-attachment-1525\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/NewCustomerOrderServiceClass.png\" alt=\"New Customer Order Service Class\" width=\"287\" height=\"148\" class=\"size-full wp-image-1525\" \/><\/a><p id=\"caption-attachment-1525\" class=\"wp-caption-text\">New Customer Order Service Class<\/p><\/div>\n<p>There are a couple of requirements for all external content types.  These stipulate that there must be a method for retrieving a single item and another for retrieving a collection of items.  We&#8217;ll start with the multiple items method.  In the <em>BDC Method Details<\/em> pane, expand the <em>Add a Method<\/em> drop down and select <em>Create Finder Method<\/em><\/p>\n<div id=\"attachment_1526\" style=\"width: 444px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/CreateFinderMethod.png\"><img aria-describedby=\"caption-attachment-1526\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/CreateFinderMethod.png\" alt=\"Create Finder Method\" width=\"434\" height=\"345\" class=\"size-full wp-image-1526\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/CreateFinderMethod.png 434w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/CreateFinderMethod-300x238.png 300w\" sizes=\"(max-width: 434px) 100vw, 434px\" \/><\/a><p id=\"caption-attachment-1526\" class=\"wp-caption-text\">Create Finder Method<\/p><\/div>\n<p>This will add a method called <em>ReadList<\/em> to the CustomerOrders entity.<\/p>\n<p>All entities require at least on identifier, so to create one right click on the entity in the diagram and select <em>Add new Identifier<\/em>.<\/p>\n<div id=\"attachment_1527\" style=\"width: 363px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewIdentifier.png\"><img aria-describedby=\"caption-attachment-1527\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewIdentifier.png\" alt=\"Add New Identifier\" width=\"353\" height=\"197\" class=\"size-full wp-image-1527\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewIdentifier.png 353w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddNewIdentifier-300x167.png 300w\" sizes=\"(max-width: 353px) 100vw, 353px\" \/><\/a><p id=\"caption-attachment-1527\" class=\"wp-caption-text\">Add New Identifier<\/p><\/div>\n<p>In this example, the identifier is called <em>OrderId<\/em>.<\/p>\n<p>To update this, select the new identifier in the entity and change the name and type to <em>OrderId<\/em> and <em>System.Int32<\/em>, which corresponds to the primary key field in the database.<\/p>\n<div id=\"attachment_1528\" style=\"width: 602px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/RenameIdentifierAndSetType.png\"><img aria-describedby=\"caption-attachment-1528\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/RenameIdentifierAndSetType.png\" alt=\"Rename Identifier and Set Type\" width=\"592\" height=\"280\" class=\"size-full wp-image-1528\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/RenameIdentifierAndSetType.png 592w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/RenameIdentifierAndSetType-300x141.png 300w\" sizes=\"(max-width: 592px) 100vw, 592px\" \/><\/a><p id=\"caption-attachment-1528\" class=\"wp-caption-text\">Rename Identifier and Set Type<\/p><\/div>\n<p>While adding the new entity to the model, a service class was automatically created for you.  We also require a class to define the fields we want used by the external content type.  Add a new class to the project called <em>CustomerOrderEntity<\/em>.<\/p>\n<div id=\"attachment_1529\" style=\"width: 316px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddCustomerOrderEntityClass.png\"><img aria-describedby=\"caption-attachment-1529\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddCustomerOrderEntityClass.png\" alt=\"Add Customer Order Entity Class\" width=\"306\" height=\"345\" class=\"size-full wp-image-1529\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddCustomerOrderEntityClass.png 306w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddCustomerOrderEntityClass-266x300.png 266w\" sizes=\"(max-width: 306px) 100vw, 306px\" \/><\/a><p id=\"caption-attachment-1529\" class=\"wp-caption-text\">Add Customer Order Entity Class<\/p><\/div>\n<p>Update the class with the following code:<\/p>\n<pre lang=\"csharp\">\r\npublic partial class CustomerOrderEntity\r\n{\r\n    public int OrderId { get; set; }\r\n\r\n    public int CustomerId { get; set; }\r\n\r\n    public string Title { get; set; }\r\n\r\n    public string Forename { get; set; }\r\n\r\n    public string Surname { get; set; }\r\n\r\n    public string Town { get; set; }\r\n\r\n    public string ItemTitle { get; set; }\r\n\r\n    public decimal Cost { get; set; }\r\n}\r\n<\/pre>\n<p>These map directly to the database view columns that will drive the content.<\/p>\n<p>Back in the model, open the <em>BDC Explorer<\/em> pane and navigate down to the <em>CustomerOrders<\/em> node within <em>ReadList<\/em>.<\/p>\n<p>From there, right click it and add a new type descriptor.<\/p>\n<div id=\"attachment_1531\" style=\"width: 309px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddTypeDescriptor.png\"><img aria-describedby=\"caption-attachment-1531\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddTypeDescriptor.png\" alt=\"Add Type Descriptor\" width=\"299\" height=\"384\" class=\"size-full wp-image-1531\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddTypeDescriptor.png 299w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AddTypeDescriptor-233x300.png 233w\" sizes=\"(max-width: 299px) 100vw, 299px\" \/><\/a><p id=\"caption-attachment-1531\" class=\"wp-caption-text\">Add Type Descriptor<\/p><\/div>\n<p>The new type descriptor is going to map to the first property in the customer order entity class that you just created.<\/p>\n<p>To do this, select the new type descriptor in the BDC Explorer pane and in the Properties pane update it so the <em>Name<\/em> is <em>OrderId<\/em> and the <em>Type Name<\/em> is <em>System.Int32<\/em>.<\/p>\n<div id=\"attachment_1532\" style=\"width: 418px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/OrderIdTypeDescriptor.png\"><img aria-describedby=\"caption-attachment-1532\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/OrderIdTypeDescriptor.png\" alt=\"OrderId Type Descriptor\" width=\"408\" height=\"716\" class=\"size-full wp-image-1532\" \/><\/a><p id=\"caption-attachment-1532\" class=\"wp-caption-text\">OrderId Type Descriptor<\/p><\/div>\n<p>Repeat this process for the remaining properties.<\/p>\n<div id=\"attachment_1533\" style=\"width: 317px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AllTypeDescriptors.png\"><img aria-describedby=\"caption-attachment-1533\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AllTypeDescriptors.png\" alt=\"All Type Descriptors\" width=\"307\" height=\"334\" class=\"size-full wp-image-1533\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AllTypeDescriptors.png 307w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AllTypeDescriptors-275x300.png 275w\" sizes=\"(max-width: 307px) 100vw, 307px\" \/><\/a><p id=\"caption-attachment-1533\" class=\"wp-caption-text\">All Type Descriptors<\/p><\/div>\n<p>With the type descriptors in place, we need to let the model know which one maps to the identifier the was added to the entity.  To do this, select <em>OrderId<\/em> in the BDC Explorer pane and in the Properties pane for it set the <em>Identifier Entity<\/em> to <em>CustomerOrders<\/em>.<\/p>\n<div id=\"attachment_1539\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetOrderByIdIdentifierEntity.png\"><img aria-describedby=\"caption-attachment-1539\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetOrderByIdIdentifierEntity.png\" alt=\"Set OrderId Identifier Entity\" width=\"400\" height=\"622\" class=\"size-full wp-image-1539\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetOrderByIdIdentifierEntity.png 400w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetOrderByIdIdentifierEntity-192x300.png 192w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><p id=\"caption-attachment-1539\" class=\"wp-caption-text\">Set OrderId Identifier Entity<\/p><\/div>\n<p>Next, set the <em>Identifier<\/em> property to <em>OrderId<\/em>.<\/p>\n<div id=\"attachment_1540\" style=\"width: 412px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetOrderIdIdentifier.png\"><img aria-describedby=\"caption-attachment-1540\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetOrderIdIdentifier.png\" alt=\"Set OrderId Identifier\" width=\"402\" height=\"516\" class=\"size-full wp-image-1540\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetOrderIdIdentifier.png 402w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetOrderIdIdentifier-233x300.png 233w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><\/a><p id=\"caption-attachment-1540\" class=\"wp-caption-text\">Set OrderId Identifier<\/p><\/div>\n<p>To complete the <em>ReadList<\/em> configuration, select the <em>CustomerOrders<\/em> node.  In the Properties pane, open the drop down for the <em>Type Name<\/em> property, change to the current project tab and select the item titled <em>CustomerOrderEntity<\/em>.  This is the class you added previously and tells the model what type of object to expect this node to process.<\/p>\n<p>With the first finder method almost complete, we&#8217;ll now add the specific finder method to allow single items to be retrieved.<\/p>\n<p>As before, expand the <em>Add a Method<\/em> drop down in the BDC Method Details pane, this time selecting <em>Create Specific Finder Method<\/em>.<\/p>\n<div id=\"attachment_1534\" style=\"width: 419px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/CreateFinderMethod1.png\"><img aria-describedby=\"caption-attachment-1534\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/CreateFinderMethod1.png\" alt=\"Create Finder Method\" width=\"409\" height=\"566\" class=\"size-full wp-image-1534\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/CreateFinderMethod1.png 409w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/CreateFinderMethod1-216x300.png 216w\" sizes=\"(max-width: 409px) 100vw, 409px\" \/><\/a><p id=\"caption-attachment-1534\" class=\"wp-caption-text\">Create Finder Method<\/p><\/div>\n<p>After doing this, all the type descriptors you manually created for the ReadList method will be automatically add to the new finder method for you.<\/p>\n<div id=\"attachment_1536\" style=\"width: 305px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AllTypeDescriptors_BothMethods1.png\"><img aria-describedby=\"caption-attachment-1536\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AllTypeDescriptors_BothMethods1.png\" alt=\"All Type Descriptors\" width=\"295\" height=\"510\" class=\"size-full wp-image-1536\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AllTypeDescriptors_BothMethods1.png 295w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/AllTypeDescriptors_BothMethods1-173x300.png 173w\" sizes=\"(max-width: 295px) 100vw, 295px\" \/><\/a><p id=\"caption-attachment-1536\" class=\"wp-caption-text\">All Type Descriptors<\/p><\/div>\n<p>Now onto the parameters for the two new methods that you just created.<\/p>\n<p>Starting with <em>ReadList<\/em>, highlight the row in the BDC Method Details pane where the direction type is return, clicking on the <em>Type Descriptor<\/em> column.<\/p>\n<p>The type name for this is currently set incorrectly and needs to map to the customer order entity class that was manually added to the project.<\/p>\n<p>To do this, open the drop down list for <em>Type Name<\/em> in the properties pane, select the tab for the current project and select the <em>CustomerOrderEntity<\/em> item.<\/p>\n<div id=\"attachment_1537\" style=\"width: 1638px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadListReturnParameter.png\"><img aria-describedby=\"caption-attachment-1537\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadListReturnParameter.png\" alt=\"Set Type Name for ReadList Return Parameter\" width=\"1628\" height=\"525\" class=\"size-full wp-image-1537\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadListReturnParameter.png 1628w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadListReturnParameter-300x96.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadListReturnParameter-1024x330.png 1024w\" sizes=\"(max-width: 1628px) 100vw, 1628px\" \/><\/a><p id=\"caption-attachment-1537\" class=\"wp-caption-text\">Set Type Name for ReadList Return Parameter<\/p><\/div>\n<p>Do the exact same for the <em>ReadItem<\/em> method.<\/p>\n<div id=\"attachment_1538\" style=\"width: 1633px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadItemReturnParameter.png\"><img aria-describedby=\"caption-attachment-1538\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadItemReturnParameter.png\" alt=\"Set Type Name for ReadItem Return Parameter\" width=\"1623\" height=\"526\" class=\"size-full wp-image-1538\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadItemReturnParameter.png 1623w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadItemReturnParameter-300x97.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/SetTypeNameForReadItemReturnParameter-1024x331.png 1024w\" sizes=\"(max-width: 1623px) 100vw, 1623px\" \/><\/a><p id=\"caption-attachment-1538\" class=\"wp-caption-text\">Set Type Name for ReadItem Return Parameter<\/p><\/div>\n<p>That should be the model complete, at least as far as this demonstration is concerned.  You&#8217;ll be able to follow similar steps to add filters that allow you to limit the number of items returned, for example.<\/p>\n<p>If you take a look at the CustomerOrderService class you&#8217;ll see a couple of methods have already been added, each one mapping to the finder method that you added via the model diagram.<\/p>\n<pre lang=\"csharp\">\r\npublic static IEnumerable<string> ReadList()\r\n{\r\n    throw new System.NotImplementedException();\r\n}\r\n        \r\npublic static string ReadItem(int orderId)\r\n{\r\n    throw new System.NotImplementedException();\r\n}\r\n<\/pre>\n<p>As mentioned at the start of this post, the purpose of this is to provide a walk through on creating a simple external content type, so I won&#8217;t go into the implementation of these methods in detail, although, if you&#8217;re interested in seeing this up and running I have provided the full source code for the sample.  You&#8217;ll find a link for this at the end of this post.<\/p>\n<p>The code that should replace the above is:<\/p>\n<pre lang=\"csharp\">\r\npublic static IEnumerable<CustomerOrderEntity> ReadList()\r\n{\r\n    IEnumerable<CustomerOrderEntity> orderEntities;\r\n\r\n    using (var dbEntities = new DemoDbModelDataContext(GetConnectionString()))\r\n    {\r\n        IList<vCustomerOrder> orderRecords = (from customerOrder in dbEntities.vCustomerOrders\r\n                                                select customerOrder).ToList();\r\n\r\n        orderEntities = from record in orderRecords\r\n                        select ConvertToCustomerOrderEntity(record);\r\n    }\r\n\r\n    return orderEntities;\r\n}\r\n\r\npublic static CustomerOrderEntity ReadItem(int orderId)\r\n{\r\n    using (var dbEntities = new DemoDbModelDataContext(GetConnectionString()))\r\n    {\r\n        vCustomerOrder customerOrderRecord = GetCustomerOrderByOrderId(dbEntities, orderId);\r\n\r\n        CustomerOrderEntity orderEntity = ConvertToCustomerOrderEntity(customerOrderRecord);\r\n\r\n        return orderEntity;\r\n    }\r\n}\r\n\r\nprivate static readonly Func<DemoDbModelDataContext, int, vCustomerOrder> GetCustomerOrderByOrderId = CompiledQuery.Compile(\r\n    (DemoDbModelDataContext context, int orderId) =>\r\n        context.vCustomerOrders.FirstOrDefault(d => d.OrderId == orderId)\r\n    );\r\n\r\nprivate static string GetConnectionString()\r\n{\r\n    var builder = new SqlConnectionStringBuilder\r\n    {\r\n        DataSource = \".\",\r\n        InitialCatalog = \"BDC_DemoDb\",\r\n        IntegratedSecurity = true\r\n    };\r\n\r\n    return builder.ConnectionString;\r\n}\r\n\r\nprivate static CustomerOrderEntity ConvertToCustomerOrderEntity(vCustomerOrder taskCtView)\r\n{\r\n    var customerOrderEntity = new CustomerOrderEntity\r\n    {\r\n        OrderId = taskCtView.OrderId,\r\n        CustomerId = taskCtView.CustomerId,\r\n        Title = taskCtView.Title,\r\n        Forename = taskCtView.Forename,\r\n        Surname = taskCtView.Surname,\r\n        Town = taskCtView.Town,\r\n        ItemTitle = taskCtView.ItemTitle,\r\n        Cost = taskCtView.Cost                \r\n    };\r\n\r\n    return customerOrderEntity;\r\n}\r\n<\/pre>\n<p>Which you can see uses the LINQ to SQL data model to access the SQL data and transforms the result to the types the BDC model expects.<\/p>\n<p><strong>Deploying<\/strong><\/p>\n<p>Once all the SQL code has been wired up, go ahead and deploy the solution.<\/p>\n<p>Once deployed, the farm scoped feature will automatically activate and create the external content type in Central Administration for the BDC service that is defined for the current web application.<\/p>\n<div id=\"attachment_1541\" style=\"width: 1614px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeployedECT.png\"><img aria-describedby=\"caption-attachment-1541\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeployedECT.png\" alt=\"Deployed ECT\" width=\"1604\" height=\"408\" class=\"size-full wp-image-1541\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeployedECT.png 1604w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeployedECT-300x76.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/DeployedECT-1024x260.png 1024w\" sizes=\"(max-width: 1604px) 100vw, 1604px\" \/><\/a><p id=\"caption-attachment-1541\" class=\"wp-caption-text\">Deployed ECT<\/p><\/div>\n<p>Drilling into the content type you can see the fields that are available.<\/p>\n<div id=\"attachment_1542\" style=\"width: 1055px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECT_ItemDefinition.png\"><img aria-describedby=\"caption-attachment-1542\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECT_ItemDefinition.png\" alt=\"ECT Item Definition\" width=\"1045\" height=\"657\" class=\"size-full wp-image-1542\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECT_ItemDefinition.png 1045w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECT_ItemDefinition-300x188.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECT_ItemDefinition-1024x643.png 1024w\" sizes=\"(max-width: 1045px) 100vw, 1045px\" \/><\/a><p id=\"caption-attachment-1542\" class=\"wp-caption-text\">ECT Item Definition<\/p><\/div>\n<p>In a site collection for the same web application, create a new external list and associate the external content type with it.  Viewing the list should present you something like the following:<\/p>\n<div id=\"attachment_1543\" style=\"width: 1451px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECTViewResults.png\"><img aria-describedby=\"caption-attachment-1543\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECTViewResults.png\" alt=\"ECT View Results\" width=\"1441\" height=\"105\" class=\"size-full wp-image-1543\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECTViewResults.png 1441w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECTViewResults-300x21.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECTViewResults-1024x74.png 1024w\" sizes=\"(max-width: 1441px) 100vw, 1441px\" \/><\/a><p id=\"caption-attachment-1543\" class=\"wp-caption-text\">ECT View Results<\/p><\/div>\n<p>For a single item:<\/p>\n<div id=\"attachment_1544\" style=\"width: 633px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECTViewItem.png\"><img aria-describedby=\"caption-attachment-1544\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECTViewItem.png\" alt=\"ECT View Item\" width=\"623\" height=\"479\" class=\"size-full wp-image-1544\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECTViewItem.png 623w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2013\/08\/ECTViewItem-300x230.png 300w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/a><p id=\"caption-attachment-1544\" class=\"wp-caption-text\">ECT View Item<\/p><\/div>\n<p><strong>Code<\/strong><br \/>\nTo download the code and database schema for this walk through, click on the following <a href=\"\/downloads\/BDCDemo.zip\">link<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Looking to design your own external content type and deploy it as part of a SharePoint solution? Read on for a walkthrough on how to create one. First up, the steps are the same for SharePoint 2010 and 2013 and &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2013\/08\/09\/external-content-type-walkthrough\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[3],"tags":[22,81],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-og","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1504"}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1504"}],"version-history":[{"count":15,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1504\/revisions"}],"predecessor-version":[{"id":1549,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1504\/revisions\/1549"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1504"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}