如何:获取 LobSystem 和 Entity

运行时对象模型提供了一个快速、只读的接口,用于读取和查询元数据存储库。本主题演示如何查询元数据存储库。

示例

此示例演示如何浏览元数据存储库并显示在业务数据目录中注册的 LobSystem 实例,以及如何获取 LobSystem 对象和 Entity 对象。

先决条件

  • 确保已创建了一个共享服务提供程序。

  • 用您的共享资源提供程序名称替换代码中的常量值 EnterYourSSPNameHere。

  • 确保在示例中引用的 LobSystem 和实体名称存在于业务数据目录中。请使用有效的名称。

项目引用

运行此示例之前,在控制台应用程序的代码项目中添加下面的项目引用:

  • Microsoft.SharePoint

  • Microsoft.SharePoint.Portal

  • Microsoft.Office.Server

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Microsoft.Office.Server.ApplicationRegistry.MetadataModel;
using Microsoft.Office.Server.ApplicationRegistry.Runtime;
using Microsoft.Office.Server.ApplicationRegistry.SystemSpecific;
using Microsoft.Office.Server.ApplicationRegistry.Infrastructure;
using WSSAdmin = Microsoft.SharePoint.Administration;
using OSSAdmin = Microsoft.Office.Server.Administration;

namespace Microsoft.SDK.SharePointServer.Samples
{
    class GetSystemAndEntity
    {
        const string yourSSPName = "EnterYourSSPNameHere";

        static void Main(string[] args)
        {
            SetupBDC();
            DisplayLobSystemsinBDC();
            GetLobSystem();
            GetEntity();
            Console.WriteLine("Press any key to exit...");
            Console.Read();
        }
        static void SetupBDC()
        {
            SqlSessionProvider.Instance().SetSharedResourceProviderToUse(yourSSPName);
        }
        static void DisplayLobSystemsinBDC()
        {
            NamedLobSystemInstanceDictionary sysInstances = ApplicationRegistry.GetLobSystemInstances();
            Console.WriteLine("Listing system instances...");
            foreach (String name in sysInstances.Keys)
            {
                Console.WriteLine(name);
            }
        }
        static void GetLobSystem()
        {
            NamedLobSystemInstanceDictionary sysInstances = ApplicationRegistry.GetLobSystemInstances();
            LobSystemInstance AdvWorksIns = sysInstances["AdventureWorksSampleInstance"];
            Console.WriteLine("Getting a system instance and displaying its ID...");
            LobSystem AdvWorksSys = AdvWorksIns.GetLobSystem();
            Console.WriteLine(AdvWorksSys.Name.ToString());
            Console.WriteLine("ID: "+AdvWorksSys.Id.ToString());
        }

        static void GetEntity()
        {
            NamedLobSystemInstanceDictionary sysInstances = ApplicationRegistry.GetLobSystemInstances();
            LobSystemInstance AdvWorksIns = sysInstances["AdventureWorksSampleInstance"];
            Console.WriteLine("Getting an entity object and displaying its ID...");
            Entity prodEntity = AdvWorksIns.GetEntities()["Product"];
            Console.WriteLine(prodEntity.Name.ToString());
            Console.WriteLine("ID: "+prodEntity.Id.ToString());
        }

    }
}

See Also

概念

业务数据目录:元数据模型

其他资源

浏览元数据存储库和执行方法及筛选器

使用业务数据目录构建自定义应用程序