Createing External Content Type with VS 2010 (1)

Difference between SP 2010 Designer and VS 2010 in terms of implementing External Content Type.

(1) Visual Studio will only allow you to build external content types whose data is provided by .NET assemblies, assemblies, which basically means that the code written in the assembly serves as a proxy for working with external data.

(2) Visual Studio uses a different concept for creating an external content type than SharePoint Designer 2010. SharePoint Designer connects directly to a live SharePoint site and writes the external content type directly in the Business Data Store. Visual Studio creates a model file (*.bdcm file) defining all the external content types. This file gets packaged together with the project output assembly and is eventually deployed as a .WSP file to SharePoint. This is useful if you work within a source control system as you can check in the model file along with your source code.

(3) Visual Studio provides a little bit more freedom
and functionality with regards to method types, search implementation, and associations.

To save (export) the BDC Model created in SP Designer 2010, Go to Central Adminà Application Management à Manage Service Applications à Business Data Connectiviry Service, and in the ribbon select BDC model from the “External Content Types” drop down.

Once done, there will be an Export button:

Once downloaded, you can add to VS 2010 project as an existing item.

——————————————————————————————–

Build a Simple External Content Type in Visual Studio

New VS 2010 project, HelloWorld, BDC project must be a farm solution.

project and BDC Model designer

Entity1 has an Identifier property called Identifier1 and two methods defined,
(1) a Finder method called ReadList and
(2) a Specific Finder method called ReadItem.

A Finder method is a method that returns a collection of entities and a Specific Finder method is a method that returns a single entity. An external content type needs to have at least one Finder method defined because this is the method called by SharePoint to get data

In BDC method details, you can see that the method ReadList has one method instance that is also called ReadList. You might wonder why we need a method instance. In the BCS runtime a method points to an abstract piece of business logic in the backend system, which is the project output assembly in the Visual Studio case. Methods are not directly executable. They become executable only when associated with a method instance.

Method instance type:

Finder – returns a collection of all entity objects

Specific Finder – Returns an emtiry object based on id

Creator – Create a new Entity object

Updater – update…
Delete – Delete…

F5 to deploy. On the Sharepoint site, Site Actions à More Options.

Select Data à External List, and enter a name.

In the next screen, give your external list a name (hello world) and select an external content type. You can look up ETC name or display all ETC.

We can say that the method ReadList of type Finder shows all the entities in the External List—in our case there was only one entity. The columns in the External List are defined by the child type descriptors of the external content type returned by the Finder method. The Specific Finder method is called when a user wants to see the details of a specific item and the fields in the details form are defined by the child type descriptors of the external content type returned by the Specific Finder method.

Build a CRUD-enabled External Content Type in Visual Studio

Create a new Spproject, empty Sharepoint project, call “Employees”.

Add a new Item, BDC Model, claled “EmployeeModel”. Delete Entity1.cs, as we will add a LINQ to SQL class to back our Employeemodel.

Add a new item, C# à Code à LINQ to SQL Class, name it Employee.dbml

Then the LINQ to SQL designer appears. In the Server Explorer, add a new data connection.

Set the connection to local SQl server, Northwind database, using Windows Auentication.

Once connectionis made, drag the Employee table to the designer area. A employee entity is created.

LINQ to SQL generates a class that we will use as our data store. Close Employee.dbml.

This is the data class file:

In the Entity Designer, rename Entity1 to Employee.


Rename the identifier to EmployeeId and change type to System.32.

(to be continued in (2))

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: