In SharePoint 2010, the Business Data Catalog has been renamed Business Connectivity Services or BCS. SharePoint 2010 also includes a new type of BCS entity based on a .NET type. Using Visual Studio 2010, you can create a .NET BCS entity to connect to data in any line-of-business system via code. In this first post of two, I will walk you through the basic set up of an entity solution in Visual Studio and how to deploy your entity to your SharePoint 2010 environment. In my next post, I will show you how to enhance your entity to support create, update, and delete operations.
In this example, we will create an Employee entity that provides an interface to employee data in a line-of-business system. In our example, the data will come from an in memory data structure, but it will be easy to see how this model could be extended to interact with a real back-end system
Below are the steps needed to implement our basic Employee entity.
1) Install the Visual Studio 2010 Tools for SharePoint 2010
Among other things, this add-on includes a Visual Studio project template for a Business Data Catalog Model. Note that in the beta, the name still refers to the Business Data Catalog. I would expect this to change before the release.
2) Create a Business Data Catalog Model project by selecting the template from within the available SharePoint related templates.
By default, your model will include an entity called Entity1 which includes an identifier, a finder method and a specific finder method. You can rename and modify this entity to suit your needs.
3) Rename the identifier and methods to better suit our scenario
This can be done right in the BDC model view itself or in the properties pane below.
4) Implement the entity class
The class should include properties for each of the data elements to be retrieved from the line-of-business system. You should also rename the class to match the name of the entity in the model. For some reason, this is not automatically synched up in the beta.
5) Implement the entity service class
Unlike the entity class, the entity service class is automatically updated to match the changes made to the entity name and method names in the model. All that remains to be done here is to implement the code needed to connect to the back-end system and implement the methods defined for the entity in the model.
For our example, we will include a static dictionary field to hold the employee data. We will also include a static initializer to populate the dictionary
Next we will implement the finder and specific finder methods. Our finder method is extremely simple. It just needs to return an IEnumerable of our entity class, so all we have to do return the Values property of our dictionary. In a real implementation, we would query the back-end system, instantiate Employee objects for each of the entities returned by the query, and then return an IEnumerable of these objects.
The final step in implementing the basic entity service class is to implement the specific finder method. Where the finder method returns an IEnumerable of our entity class, the specific finder method returns a single entity based on an identifier passed in as a parameter. In our implementation, we will use the employee’s SSN as a key into the static dictionary and will return a new Employee instance based on the data from the dictionary instance.
Now we have a complete read-only entity that could be deployed to Business Connectivity Services and used in our SharePoint sites. However, one of the most powerful features of Business Connectivity Services in SharePoint 2010 is the support for read/write entities. In my next post, I will show you how to implement the create, update, and delete operations to turn our Employee entity into a read/write entity.