This topic has not yet been rated - Rate this topic

BDC Programming Model

SharePoint 2010

Published: May 2010

In Sample BDC Model, we described a Customer external content type. Let's assume the structure of the Customer external content type appears as Customer (Name, ID, Phone no., Address), where address is another complex type.

After you define the model for the Customer external content type for a given external data source and save it in the BDC Metadata Store, the BDC code used to interact with the Customer external content type (create, read, update, delete) appears the same, regardless of whether the back-end is a database, a Web service, or a .NET connectivity assembly. This is the primary advantage of this programming pattern: Regardless of the type of the external data source that the application is trying to interact with, the code will look exactly the same.

Example: BDC code that creates a Customer instance in the external data source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.BusinessData.SharedService;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.Runtime;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
using System.Web;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://ssdk-server/Pages/Default.aspx"))
                {
                    using (new Microsoft.SharePoint.SPServiceContextScope(SPServiceContext.GetContext(site)))
                    {
                        BdcService service = SPFarm.Local.Services.GetValue<BdcService>(String.Empty);
                        IMetadataCatalog catalog = service.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);

                        IEntity entity = catalog.GetEntity("http://ssdk-server/sdksamples", "Customer");
                        ILobSystemInstance LobSysteminstance = entity.GetLobSystem().GetLobSystemInstances()[0].Value;


                        IView createView = entity.GetCreatorView("Create");
                        IFieldValueDictionary valueDictionary = createView.GetDefaultValues();
                        valueDictionary["Name"] = "some name";
                        Identity id = entity.Create(valueDictionary, LobSysteminstance);
                    }
                }
            }
        }
 }

Example: BDC code that enumerates Customer instances in the BCS client cache on the client

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.Runtime;
using Microsoft.Office.BusinessData.MetadataModel;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            RemoteSharedFileBackedMetadataCatalog RemoteCatalog = new RemoteSharedFileBackedMetadataCatalog();
            IEntity remoteEntity = RemoteCatalog.GetEntity("http://ssdk-server/sdksamples", "Customer");
            ILobSystemInstance LobSysteminstance = remoteEntity.GetLobSystem().GetLobSystemInstances()[0].Value;
 
            IMethodInstance method = remoteEntity.GetMethodInstance("Read List", MethodInstanceType.Finder);
            IEntityInstanceEnumerator ieie = remoteEntity.FindFiltered(method.GetFilters(), LobSysteminstance);
            IView view = remoteEntity.GetFinderView(method.Name);
            while (ieie.MoveNext())
            {
                foreach (IField field in view.Fields)
                {
                    if (ieie.Current[field] != null)
                    {
                        Console.WriteLine(ieie.Current[field].ToString());
                    }
                }
            }
       }
   }
} 

Date

Description

Reason

May 2010

Initial publication

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Namespace
I think you might be able to find the equivalent one using Microsoft.SharePoint.BusinessData.Runtime
The type or namespace ... does not exists in the namespace ...
Couldn't compile this because Microsoft.BusinessData and Microsoft.Office.Business did not exist in the namespace ... I eventually resolved Microsoft.BusinessData because other work I'd done recently caused the correct dll to appear in a short list of recent dll's. I have no idea what dll to specifically reference to fix "Microsoft.Office.Business"