上次修改时间: 2010年5月6日
适用范围: SharePoint Server 2010
本文内容
说明
先决条件
使用此示例
说明
下面的代码示例演示如何通过使用服务器上的 BDC 运行时对象模型,以编程方式执行外部内容类型的 BulkSpecificFinder 方法实例。
先决条件
Microsoft SharePoint Server 2010 或 Microsoft SharePoint Foundation 2010 位于服务器上。
Microsoft .NET Framework 3.5 和 Microsoft Visual Studio 位于客户端上。
使用此示例
启动 Visual Studio 并创建一个 C# 控制台应用程序项目。在创建此项目时,请选择".NET Framework 3.5"。
从"视图"菜单中,单击"属性页"以显示项目属性。
在"生成"选项卡中,为"目标平台"选择"任何 CPU"。
关闭项目属性窗口。
在"解决方案资源管理器"中的"引用"下,删除 System 和 System.Core 之外的所有项目引用。
将以下引用添加到项目中:
Microsoft.BusinessData
Microsoft.SharePoint
System.Web
将 Program.cs 中自动生成的代码替换为此过程结束时列出的代码。
将 <ID> 值和 SiteURL 值替换为有效的值。
此示例基于 AdventureWorks 示例数据库和 SalesOrder 外部内容类型。如果您的外部系统不一样,则在适用的代码中更改外部内容类型和 LobSystem 的名称。
保存项目。
编译并运行项目。
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)