In my previous post, I went through the details of setting up a read-only BCS entity using Visual Studio. Now we will explore how to make our entity read/write.
To add create, update, and delete capabilities to our entity we first need to go add these methods to our entity in the model.
1) Add a create method to the model
To add a create method, go to the BDC Method Details pane in the model view, pull down the Add a Method dropdown, and select Create Creator Method.
Update the details of the method as shown below.
The create method has parameters for each of the data elements on the entity and returns the identifier of the newly created entity.
2) Add an update method to the model
To add an update method, go to the BDC Method Details pane in the model view, pull down the Add a Method dropdown, and select Create Updater Method.
Update the details of the method as shown below.
The update method has a single parameter that accepts the updated employee entity and has no return value.
3) Add an delete method to the model
To add a delete method, go to the BDC Method Details pane in the model view, pull down the Add a Method dropdown, and select Create Deleter Method.
Update the details of the method as shown below.
The delete method has a single parameter that accepts the employee entity to be deleted.
4) Implement the create method
After you add the Create method to the model, Visual Studio will also add a stub to the EmployeeService class. The stub should have a signature that matches the parameter list included in the model.
Our implementation will create a new Employee instance, set its property values, and then add it to the dictionary. In a real implementation, our code would communicate with the back-end system to create the entity.
5) Implement the update method
As with the Create method, Visual Studio will add a stub Update method to the EmployeService class based on the parameter list in the model.
Our implementation will retrieve the employee entity from the dictionary and will update its property values based on the updated entity passed into the method.
6) Implement the delete method
Visual Studio has also created a stub Delete method based on our model specification.
Our implementation will simply remove the Employee from the dictionary.
7) Deploy the WSP to your development environment
With Visual Studio 2010 Tools for SharePoint 2010 installed, Visual Studio 2010 now includes the capability to package and deploy SharePoint solutions.
If we look at the Solution Explorer pane, we will notice that the project template included a feature and a package. The feature will be used to activate the BCS entity at the farm level. The package will create a WSP that we can use to deploy the feature and the assembly that includes our entity classes. Both the feature and the package should work just fine with their default configurations. We do not have to change anything in these files.
To build and deploy our WSP, simply pull down the Build menu and select the option to deploy the project. This will build the project, create the WSP, and deploy it to the development server specified when the project was first created. This setting is stored in the csproj.user associated with the project.
If we look in the Business Connectivity Services administration screen in Central Administration, we will see that our Employee entity is now available as an external content type.
We can leverage our entity by creating an external list in any of our sites. First, go to the create page for the site and click External List.
Then name the new list and select the entity type that will be used for the list.
Once the list is created, we can use it like any other SharePoint list. The only difference from an end-user perspective is that the list is reading from and updating to a back-end system instead of the SharePoint content database.