Code Snippet: Execute the BulkSpecificFinder Method Instance of an External Content Type
마지막 수정 날짜: 2010년 5월 6일 목요일
적용 대상: SharePoint Server 2010
이 문서의 내용
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
Start Visual Studio and create a C# Console application project. Select .NET Framework 3.5 when you create the project.
From the View menu, click Property Pages to bring up the project properties.
In the Build tab, for the Platform target, select Any CPU.
Close the project properties window.
In Solution Explorer, under References, remove all project references except for System and System.Core.
Add the following references to the project:
Microsoft.BusinessData
Microsoft.SharePoint
System.Web
Replace the autogenerated code in Program.cs with the code listed at the end of this procedure.
Replace the <ID> values and the SiteURL value with valid values.
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.
Save the project.
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();
}
}
}
}
}
}
}
참고 항목
참조
GetDatabaseBackedMetadataCatalog(SPServiceContext)
FindSpecificMultiple(IList<Identity>, String, ILobSystemInstance, OperationMode)