How to develop and deploy the ECTs/BDC Models to multiple environments

Up to this point I have discussed creating ECTs and BDC Models and Resources in SPD, VS, notepad, and Central Admin. So which should we be really using? I will first discuss each of these platforms:

SharePoint Designer
is free tool from Microsoft that can provide no-code solution to creating BDC Models and ECTs. It will provide for rapid development without writing any code or markup, but has two major drawbacks. First, the solution will not be searchable as stated in Issue 3. Second, the solution will be specific to a SharePoint site that you are required to identify before developing your solution and you will not be able to deploy your solution to a different site.

If neither of the drawbacks is an issue for you, then SPD is a wonderful tool for your BCS development. It will even allow you to create External Lists (among other things) based on your ECTs with a push of a button.

Visual Studio (2010)
Another tool from Microsoft that will allow you to create BDC Models, Resources, and ECTs with code or XML markup. Although it is not free, no SharePoint developer should develop without it. It has no limitations on your BCS solution and will allow you to package and deploy your BCS Solution to multiple sites. It’s only true drawback is that you will either need to write code or XML markup for your solution and can therefore not really be recognized as a rapid development platform.

Notepad (or your favorite text editor)
Since you can develop BCS Solutions using only XML markup, there is nothing stopping you from writing your XML in your favorite text editor. This however is no small feat as you will need to be very familiar with all the necessary BCS tags and all their necessary attributes. In addition, this approach is very error prone.

Central Admin
Although Central Admin is not a development platform; it will however allow you to do certain things that will make your development easier. Central Admin will allow you to import and export both .bdcm and .bdcr files. This means that if you do develop your solution in either Notepad or SPD (or even VS for that matter), Central Admin will allow you to import those files, strip out or add resources, and then allow you to export the new model or resources. This is incredibly useful if you want to take a solution built in SPD for example which is targeted to a specific site, strip out all site specific information, and then export out a true BDC Model that can then be implemented on any SharePoint site.

There are also third-party platforms that provide much of the capabilities of SPD without some of the limitations in creating and implementing BCS Solutions that are worth investigating.

So which of the above would you think is the best way to go?

Well, the answer turns out to be a combination of the platforms above, taking advantage of each of the above platform’s capabilities and using another platform to overcome the drawbacks of the first. Below is the process I used to rapidly develop a solution that is both searchable and deployable to multiple environments:

  1. Create all the required ECTs for a given BDC Model in SPD
    1. Include at least a Finder and a Specific Finder method for each ECT
    2. Include any other necessary operations for each ECT
    3. Define any associations for each ECT
    4. Identify a field to mark as a Title field for each ECT
  2. Select all the ECTs and export them out as a single BDC Model
  3. Save that model as a .bdcm file on your local system
  4. Import the .bdcm file into (the BCS Service Application on) CA
  5. Export the model out of CA as a different .bdcm file then was imported into it
    1. Make sure to uncheck any resource checkboxes prior to exporting as a BDC Model (this strips out any resources out of your BDC Model)
  6. Open VS and create a new (or open an existing) Blank SharePoint 2010 project
  7. Add a new BDC Model item
  8. Delete the generated Entity1.cs and the Entity1Service.cs files
  9. Open the .bdcm file (using an XML editor within VS)
    1. Right-Click the .bdcm file and choose Open With…
  10. Delete all content in the .bdcm file in VS
  11. Open the .bdcm file exported from CA with Notepad (or your favorite simple text editor)
  12. Copy all content and paste it into the .bdcm file in VS
  13. Make all the necessary changes to make the model searchable (see Issue 3)
  14. If deploying from VS, then open the newly created Feature.Template.xml file and add the following markup:
    <?xmlversion=”1.0″encoding=”utf-8″ ?>
    <Feature xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
    <Properties>
    <Property Key=’SiteUrl’ Value=’http://YourDevSite‘/>
    </Properties>
    </Feature>

    1. Note that for each BDC Model, there is a SharePoint feature (you cannot have more than one model per feature)
    2. The feature will be scoped to the Farm level (as all BCS Solutions are defined at the Farm level in CA)
    3. You should only deploy from VS for development purposes, for Integration, QA, or production deployments, you should use PowerShell
  15. Right-Click on your project and choose to package your solution
  16. Go to your Bin folder in your project from your file system and copy the WSP file that is generated when you performed step 15
  17. Save the WSP onto the SP Application Server that you want your solution deployed to
  18. Deploy and Activate your WSP package to the target SP Application Server
  19. Go to the BCS Service Application in CA and select the BDC Model that was just deployed
  20. 20. Right-Click the model and choose to Set Permissions
  21. Add all the accounts that will need the appropriate permissions to your BDC model and click OK

And you are done…Only 21 steps, not a lot ;).

BDC Models, Resource files, and making Content Types Searchable

As stated earlier, SharePoint Content Types (including ECTs) represent entities and encapsulate all the necessary metadata about those entities. BDC Models represent a collection of ECTs and any relationships between those ECTs. So if you wanted to represent publishers and books and associate all the books published by each publisher, you would need to define the publishers, books, and their association within one BDC Model. BDC Models can be implemented in code via Visual Studio (VS) or can be implemented using XML via VS, SPD, or notepad. If they are implemented using XML, then the resulting file is referred to as the BDC Model (.bdcm).

BDC Models could include other information such as permissions for the ECTs, system or line of business properties, localized names, or proxies, but these types of information are considered resources and are best either implemented in Central Admin or placed in BCS Resource files (.bdcr). These can also be implemented via code in VS, but it is not usually a good practice.

Now although you can create a BDC Model, that doesn’t mean that you can search that model in SharePoint Enterprise (or FAST) Search just yet. You will have to mark the Model and each ECT as searchable. You will also need to create a profile page for at least each model and may create a profile page for each ECT. It is important to note that none of the steps necessary to make your solution searchable can be implemented directly in SPD, you will either have to open your model in notepad or VS and make XML changes for this to work. I will go into further detail about exactly how to do this in a future blog.

Why choose a BCS solution?

Surfacing external data in SharePoint enables users to build composite applications that give access to critical information and make their interactions with that information more convenient.  Business Connectivity Services (BCS) is the SharePoint service which allows surfacing of external data from SQL Server, Web Services, or.NET Assembly Connector.  SharePoint even provides no-code BCS solutions to surface the external data via SharePoint Designer to allow for rapid development and provides External Lists to quickly interacting with that data.  You can also secure the data by setting permissions on who can create, read, update, and delete (CRUD) the data.  You can even crawl that data using SharePoint Enterprise Search and set a profile page for rendering the search results in a meaningful way.  You can rapidly developing a feature rich front end for your external data.

Search enabling your BCS solution will however require more than SharePoint Designer to develop.  This is also true if you want to deploy your solution to multiple environments.  This does not mean that you have to write code, but it does mean that you will find yourself in Visual Studio modifying declarative markup that SharePoint Designer can produce and packaging that markup into WSP solution packages.  This approach will allow you to develop external data solutions that you can quickly develop and deploy to multiple environments consistently and will provide your users the ability to immediately search and render meaningful results.

Now if you do determine that you need to integrate external data with SharePoint, but want to still have custom forms or any kind of richer user experience to interact with that data, you could write code using the SharePoint API against external lists.  This approach is often touted as one of the great things about external lists in that you can treat them as any other SharePoint lists.  This approach will work for small datasets, but for large datasets and anytime you are concerned about performance of your forms, you will really want to write your code to go against the BCS Runtime or Client Object Models.  This is a very powerful approach as you can now develop a very rich custom user interface to interact with your external data within the SharePoint context.  You can even access your external data from other applications via the BCS Client Object Model.

As I have discussed, SharePoint provides for rapid development of external data and allows you to apply security and search on your external data.  It also provides the capability to build very powerful and very rich custom user experiences for your external data.  Implementing these solutions to different environments and making your application production ready presents some challenges that are not well documented.  In my next few blog posts, I will go through the process of making an external data solution from beginning to end and show you techniques that will make your solution more stable and production ready.