Compartilhar via


Code Snippet: Execute the BulkSpecificFinder Method Instance of an External Content Type

Applies to: SharePoint Server 2010

In this article
Description
Prerequisites
To use this example

Description

The following code example shows how to programmatically execute a BulkSpecificFinder method instance of an external content type by using the BDC Runtime object model on the server.

Prerequisites

  • Microsoft SharePoint Server 2010 or Microsoft SharePoint Foundation 2010 on the server.

  • Microsoft .NET Framework 3.5 and Microsoft Visual Studio on the client.

To use this example

  1. Start Visual Studio and create a C# Console application project. Select .NET Framework 3.5 when you create the project.

  2. From the View menu, click Property Pages to bring up the project properties.

  3. In the Build tab, for the Platform target, select Any CPU.

  4. Close the project properties window.

  5. In Solution Explorer, under References, remove all project references except for System and System.Core.

  6. Add the following references to the project:

    1. Microsoft.BusinessData

    2. Microsoft.SharePoint

    3. System.Web

  7. Replace the autogenerated code in Program.cs with the code listed at the end of this procedure.

  8. Replace the <ID> values and the SiteURL value with valid values.

  9. This sample is based on the AdventureWorks sample database and the SalesOrder external content type. If your external system is different, change the name of the external content type and LobSystem as appropriate in the code.

  10. Save the project.

  11. Compile and run the project.

using System;
using System.Collections.Generic;
using Microsoft.SharePoint.BusinessData.SharedService;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.MetadataModel.Collections;
using Microsoft.BusinessData.Runtime;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
 
namespace SDKSamples
{
    class Methods
    {
 
         static void Main(string[] args)
         {
            List<Identity> identities = new List<Identity>();
            identities.Add(new Identity(<ID1>));
                        identities.Add(new Identity(<ID2>));
            identities.Add(new Identity(<ID3>));
            identities.Add(new Identity(<ID4>));
            FindMultipleSalesOrderById(identities);
         }
 
         // BulkSpecificFinder.
         public static void FindMultipleSalesOrderById(
            IList<Identity> identities)
         {
            string SiteURL = "<siteUrl>";
 
            using (SPSite site = new SPSite(SiteURL))
            {
                using (new Microsoft.SharePoint.SPServiceContextScope(
                   SPServiceContext.GetContext(site)))
                {
                    BdcService service =
                        SPFarm.Local.Services.GetValue<BdcService>(String.Empty);
                    IMetadataCatalog catalog =
                        service.GetDatabaseBackedMetadataCatalog(
                        SPServiceContext.Current);
 
                    // Get entity.
                    IEntity salesOrderEntity = catalog.GetEntity(
                        "AdventureWorks", "SalesOrder");
 
                    // Get LOB System instance.
                    ILobSystemInstance lobSystemInstance =
                        salesOrderEntity.GetLobSystem().
                        GetLobSystemInstances()["AdventureWorks"];
 
                    IEntityInstanceEnumerator orders = null;
 
                    try
                    {
                        // Read the given identities.
                        orders = salesOrderEntity.FindSpecificMultiple(
                            identities,
                            "Bulk Read Item",
                            lobSystemInstance,
                            OperationMode.Online);
 
                        // List found orders.
                        while (orders.MoveNext())
                        {
                            Console.WriteLine(
                                String.Format(
                                "Id: {0}, OrderDate: {1}",
                                orders.Current["SalesOrderID"],
                                orders.Current["OrderDate"]));
                        }
                    }
                    finally
                    {
                        // Ensure the enumerator is closed.
                        if (orders != null)
                        {
                            orders.Close();
                        }
                    }
                }
            }
        }
    }
}

See Also

Reference

Identity

BdcService

Services

IMetadataCatalog

GetDatabaseBackedMetadataCatalog(SPServiceContext)

GetEntity(String, String)

IEntity

GetLobSystem()

GetLobSystemInstances()

ILobSystemInstance

IEntityInstanceEnumerator

FindSpecificMultiple(IList<Identity>, String, ILobSystemInstance, OperationMode)