{"id":592,"date":"2010-08-18T14:07:09","date_gmt":"2010-08-18T12:07:09","guid":{"rendered":"http:\/\/www.itidea.nl\/?p=592"},"modified":"2015-09-08T20:31:17","modified_gmt":"2015-09-08T18:31:17","slug":"bcs-model-a-simple-read-only-model","status":"publish","type":"post","link":"https:\/\/www.itidea.nl\/index.php\/bcs-model-a-simple-read-only-model\/","title":{"rendered":"BCS model \u2013 a simple read only model"},"content":{"rendered":"<p>In the first part, <a href=\"https:\/\/www.itidea.nl\/index.php\/bcs-model-some-basics\/\">BCS model \u2013 some basics\u00a0<\/a>, I talked about the items Visual Studio creates for you, the meaning of these items and some about renaming files. The next step is to create a simple model to show the functionality\u00a0of the model.\u00a0\u00a0<\/p>\n<p>Just create a new project in Visual Studio based on the template \u2018Business Data Connectivity Model\u2019 and give the project a name. In the next screen you can see a BSC model can be deployed only as a <span style=\"text-decoration: underline;\">farm solution<\/span>, not a sandboxed solution, and select the site for debugging.\u00a0\u00a0<\/p>\n<p>Rename the class Entity1 to Customer, rename the file Entity1.cs to Customer.cs and update the design view of the model (.bdcm) by setting the name of the entity to Customer. By the last rename the Entity1Service is automatically renamed to CustomerService. A quick refresh of the previous post: \u2018The entity on the design has a custom property which points to the entity service. With this connection the code in the service can be adjusted to the changes made in the design surface or BDC Method Details.\u2018<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCCustomPropertyConnectionToService.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-623 alignnone\" title=\"BDCCustomPropertyConnectionToService\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCCustomPropertyConnectionToService.png\" alt=\"\" width=\"599\" height=\"203\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCCustomPropertyConnectionToService.png 1041w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCCustomPropertyConnectionToService-300x101.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCCustomPropertyConnectionToService-1024x347.png 1024w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/a><\/p>\n<p>Delete the methods at the BDC Method Details window and clean the CustomerService by deleting the methods.<br \/>\nChange the Customer entity to:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\u00a0\u00a0\u00a0 public partial class Customer\r\n\u00a0\u00a0\u00a0 {\r\n        public int CustomerId { get; set; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public string CustomerName { get; set; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public string CustomerCity { get; set; }\r\n\u00a0\u00a0\u00a0 }\r\n<\/pre>\n<p>And update the design view by renaming Identifier1 to CustomerId and change its type to System.Int32. All in sync now.\u00a0\u00a0<\/p>\n<p>Now let\u2019s create the methods for the entity and start with the simplest one, a Finder method to list all the Customers.<br \/>\nIn the BDC Method Details window select \u2018Add a method\u2019 and \u2018Create Finder Method\u2019. The ReadList method is created now with a return type descriptor with the name CustomerList. Since this is just a name, check the Type Name in the properties window: System.Collections.Generic.IEnumerable`1[System.String]<br \/>\nWe have to change the generic list of strings to a generic list of Customers by selecting the arrow next to the type, select the tab Current Project and select the Customer entity.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCSelectType1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-625\" title=\"BDCSelectType\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCSelectType1.png\" alt=\"\" width=\"443\" height=\"406\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCSelectType1.png 443w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCSelectType1-300x274.png 300w\" sizes=\"auto, (max-width: 443px) 100vw, 443px\" \/><\/a><\/p>\n<p>The type name changed now to:<br \/>\nSystem.Collections.Generic.IEnumerable`1[[ITIdea.BCSBasics.BdcModel1.Customer, BdcModelSub]]<br \/>\nAnd the CustomerService class is updated as well.The return type of the method is a generic list of Customer objects. The next thing we have to do is to specify our Customer object to return the fields representing the Customer object. Therefor we have to add additional type descriptors at the Customer return type at the BDC Explorer.\u00a0<\/p>\n<p>Select in the BDC Explorer to the Customer type descriptor of the ReadList method. Right click and select Add Type Descriptor. Change the name to CustomerId and the type to System.Int32, set the Identifier property to CustomerId and ReadOnly to True. Add two others with the name CustomerName and type System.String and the name CustomerCity and type System.String.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCTypeDescriptors.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-626\" title=\"BDCTypeDescriptors\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCTypeDescriptors.png\" alt=\"\" width=\"218\" height=\"119\" \/><\/a><\/p>\n<p>When you don\u2019t define the object and you create a list based on the entity (External Content Type) you will receive the following message when displaying the list:<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNoTypeDescriptorsReadList.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-627\" title=\"BDCNoTypeDescriptorsReadList\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNoTypeDescriptorsReadList.png\" alt=\"\" width=\"576\" height=\"39\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNoTypeDescriptorsReadList.png 576w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNoTypeDescriptorsReadList-300x20.png 300w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/a><\/p>\n<p>To retrieve one customer at a time we create a Specific Finder method.\u00a0\u00a0<\/p>\n<p>In the BDC Method Details window select \u2018Add a method\u2019 and \u2018Create Specific Finder Method\u2019. The ReadItem method is created with two parameters: a return parameter customer and an input parameter customerId. The type descriptor\u2019s type name of the customer parameter is set the System.String at the properties window, change this to return a Customer type.<br \/>\nThe other type descriptors are already there because we defined them at the ReadList method.\u00a0\u00a0<\/p>\n<p>The last thing we have to do now is to write some implementation of our methods ReadItem and ReadList. Now change these method to return just one Customer at ReadItem and a list of Customers at ReadList.\u00a0\u00a0(I will\u00a0 leave this for your own fantasy, I use a Linq to Sql class to quickly connect to a table in a database)<\/p>\n<p>Deploy the project and create a list based on this External Content type.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCViewExternalList.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-631\" title=\"BDCViewExternalList\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCViewExternalList.png\" alt=\"\" width=\"821\" height=\"77\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCViewExternalList.png 1140w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCViewExternalList-300x28.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCViewExternalList-1024x96.png 1024w\" sizes=\"auto, (max-width: 821px) 100vw, 821px\" \/><\/a><\/p>\n<p>As you notice you can view all the Customers you defined in the ReadList method and you can view the details of one customer.<br \/>\nOf course you can change the displayname of the columns to whatever you want by changing the Default Display Name at the properties of a specific Type Descriptor in Visual Studio.\u00a0\u00a0<\/p>\n<p>In case you don&#8217;t see the contents of the list, check <a href=\" https:\/\/www.itidea.nl\/index.php\/bcs-possible-errors\/\">BCS\u00a0&#8211; possible errors<\/a>.<\/p>\n<p>This is all great but it would be really nice to add new items and edit existing ones &#8211;&gt; will be my next post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the first part, BCS model \u2013 some basics\u00a0, I talked about the items Visual Studio creates for you, the meaning of these items and some about renaming files. The next step is to create a simple model to show &#8230; <a class=\"more-link\" href=\"https:\/\/www.itidea.nl\/index.php\/bcs-model-a-simple-read-only-model\/\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[32,42,6],"class_list":["post-592","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2010","tag-bcs","tag-sharepoint-2010","tag-visual-studio"],"_links":{"self":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/comments?post=592"}],"version-history":[{"count":27,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/592\/revisions"}],"predecessor-version":[{"id":648,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/592\/revisions\/648"}],"wp:attachment":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/media?parent=592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/categories?post=592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/tags?post=592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}