代码段:获取服务器上的 DatabaseBackedMetadataCatalog

上次修改时间: 2010年5月5日

适用范围: SharePoint Server 2010

本文内容
说明
必备组件
使用该示例

说明

下面的代码示例演示如何使用服务器上的 Business Data Connectivity (BDC) Service 运行时对象模型来获取服务器上的 DatabaseBackedMetadataCatalog。

必备组件

  • 服务器上安装了 Microsoft SharePoint Server 2010 或 Microsoft SharePoint Foundation 2010

  • Microsoft .NET Framework 3.5 和 Microsoft Visual Studio

  • BDC 元数据存储中至少已注册了一个外部内容类型

使用该示例

  1. 启动 Visual Studio,然后创建一个新的 C# 控制台应用程序项目。在创建项目时,选择".NET Framework 3.5"。

  2. 从"视图"菜单中,选择"属性页"以显示项目属性。

  3. 在"生成"选项卡上,为"目标平台"选择"任何 CPU"。

  4. 关闭项目属性窗口。

  5. 在"解决方案资源管理器"中的"引用"下,移除除 SystemSystem.Core 以外的所有项目引用。

  6. 将以下引用添加到项目中:

    1. Microsoft.BusinessData(位于 SharePoint_RootFolder\ISAPI 中)

    2. Microsoft.SharePoint

  7. 用此过程末尾列出的代码替换 Program.cs 中自动生成的代码。

  8. 使用有效值替换 <siteUrl>、<nameSpace>、<lobsystemInstance> 和 <entityName> 的占位符值。

  9. 保存该项目。

  10. 编译该项目。

  11. 在安装了 SharePoint Server 2010 或 SharePoint Foundation 2010 的服务器计算机上运行应用程序。

using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.Runtime;
using Microsoft.SharePoint.BusinessData.MetadataModel;
using Microsoft.SharePoint;
using Microsoft.SharePoint.BusinessData.SharedService;


//Code.

// Get context from specific site.
SPServiceContext context = SPServiceContext.GetContext(new SPSite("<siteUrl>")); 
IMetadataCatalog databaseCatalog = null;
BdcService bdcService = SPFarm.Local.Services.GetValue<BdcService>(String.Empty);
if (null != bdcService)
{
    databaseCatalog = bdcService.GetDatabaseBackedMetadataCatalog(context);
}
string @namespace = "<nameSpace>";
string entityName = "<entityName>";
string lsiName = "<lobsystemInstance>";

IEntity entity = databaseCatalog.GetEntity(@namespace, entityName);
ILobSystem lobSystem = entity.GetLobSystem();
ILobSystemInstance lsi = lobSystem.GetLobSystemInstances()[lsiName];

请参阅

引用

IMetadataCatalog

BdcService

GetDatabaseBackedMetadataCatalog(SPServiceContext)

GetEntity(String, String)

IEntity

GetLobSystem()

ILobSystem

GetLobSystemInstances()

ILobSystemInstance