IT tutorials
 
Technology
 

Sharepoint 2010 : Business Connectivity Services - The BCS Object Model

9/17/2013 1:28:15 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

And that huge advantage, is the ability to represent any back-end system, in a consistent object model that can be programmed against. This object model is the BCS object model. What this means is that as the back-end systems change and upgrade over time, as long as their equivalent BCS external content types are kept up to date, all existing systems can continue to leverage the same object model, and existing systems will continue to work with changing newer versions of back-end systems without even the need of a recompile. This is because, as long as you update the BCS external content types, the actual BCS object model won't change, and will continue to work and will simply reflect the updated external content types.

The sample that I am about to show assumes that you have the "NorthWind Customer" external content type setup in your system. The BCS object model provides you with functionality to both query and maintain the catalog, or to execute methods on individual external content types.

Start Visual Studio 2010 and create a .net 3.5 console application. Make sure the target platform is AnyCPU, and add the following references.

  • C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.Sharepoint.dll

  • C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.BusinessData.dll

  • Microsoft.Sharepoint.BusinessData.Administration.Client.dll from the GAC

In your console application add a static variable pointing to your SharePoint site as shown below:

privatestaticstringsiteUrl = "http://sp2010";

The you can browse through the existing catalog by using the AdministrationMetaDataCatalog object in the Microsoft.Sharepoint.BusinssData.Administration.Client namespace. This can be seen in Listing 1.

Example 1. Browsing through the catalog on your Sharepoint installation.
private static void BrowseCatalogDetails()
{
Console.WriteLine("Now Browsing the details of the catalog:");
AdministrationMetadataCatalog catalog =
AdministrationMetadataCatalog.GetCatalog(siteUrl);
EntityCollection entities = catalog.GetEntities("*", "*", true);
Console.WriteLine("\nEntities in the system:");
foreach (Entity entity in entities)
{
Console.WriteLine(entity.Name);
}

// Lets pick the first entity
var entityEnum = entities.GetEnumerator();
entityEnum.MoveNext();
Entity firstEntity = entityEnum.Current;
Console.WriteLine("\nMethods on the first Entity:");
foreach (var method in firstEntity.Methods)
{
Console.WriteLine(method.Name);
}
}

As you can see from Listing 1, you have access to all the entities and all the details of all the entities in the catalog. In fact if you poke around the object model, you will be able to find that purely through the object model you can create the new entities in the catalog as well. This is very similar to what used to be able to do in SharePoint 2007 using the BDC object model. However there is one big difference that may not be very apparent! Note that the Microsoft.Sharepoint.BusinssData.Administration.Client namespace is actually part of the client stack. In other words, the code shown above does not need to run on the server! In SharePoint 2007 you were required to run this code on the machine that was running the SSP and then expose it as a web service. That is no longer necessary.

Next let us look at an example of actually executing a method on an entity, and writing the results out. This can be seen in Listing 2.

Example 2. Executing a method and writing the results out.
private static void ExecuteMethod()
{
Console.WriteLine("\nNow Executing methods");
using (SPSite site = newSPSite(siteUrl))
{
using (newSPServiceContextScope(SPServiceContext.GetContext(site)))
{
BdcService service = SPFarm.Local.Services.GetValue<BdcService>();
IMetadataCatalog catalog =
service.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);

IEntity entity = catalog.GetEntity(siteUrl, "Northwind Customer");
ILobSystemInstance LobSysteminstance =
entity.GetLobSystem().GetLobSystemInstances()[0].Value;

IMethodInstance method =
entity.GetMethodInstance("Read List", MethodInstanceType.Finder);
IEntityInstanceEnumerator ieie =
entity.FindFiltered(method.GetFilters(), LobSysteminstance);

Console.WriteLine("\nCustomers in Northwind:");
while (ieie.MoveNext())
{
Console.WriteLine(ieie.Current["ContactName"].ToString());
}
}
}
}


As you can see from Listing 2, I'm able to use a consistent object model, irrespective of the details of the external content type, or the back-end system, and be able to execute methods on the back-end system. Thus as the back-end system changes, and the external content type is maintained, the code shown in Listing 2 will remain unchanged. This is the value that BCS offers! Also if you poke through the object model further, you will see significant enhancements in the object model over the SharePoint 2007 equivalent. For instance in SharePoint 2010, you now have support for bulk operations, and for reading blob types with streaming support.

 
Others
 
- Sharepoint 2010 : Business Connectivity Services - BCS with Visual Studio 2010
- Sharepoint 2010 : Business Connectivity Services - BCS and SharePoint Designer
- Windows Phone 8 : Services - Consuming OData (part 2) - Generating a Service Reference for OData, Retrieving Data, Updating Data
- Windows Phone 8 : Services - Consuming OData (part 1) - How OData Works, The URI
- Windows Home Server 2011 : Using File Server Resource Manager (part 2) - Creating a Quota, Creating a File Screen
- Windows Home Server 2011 : Using File Server Resource Manager (part 1) - Creating a Quota Template
- Windows Home Server 2011 : Managing Storage - Using Folder Redirection
- System Center Configuration Manager 2007 : Patch Management - Software Updates Process (part 5) - Update Deployments, Deployment Packages
- System Center Configuration Manager 2007 : Patch Management - Software Updates Process (part 4) - Update Lists, Deployment Templates
- System Center Configuration Manager 2007 : Patch Management - Software Updates Process (part 3) - Update Repository
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us