How to: Get an LobSystem and an Entity

The Runtime object model offers a fast, read-only interface for reading and querying the metadata repository. This topic shows how to query the metadata repository.

Example

This example shows how to browse the metadata repository and display the LobSystem instances registered in the Business Data Catalog, and how to get an LobSystem object and an Entity object.

Prerequisites

  • Ensure a Shared Service Provider is already created.

  • Replace the constant value EnterYourSSPNameHere in the code with the name of your Shared Resource Provider.

  • Make sure the LobSystem and entity names referenced in the example exist in the Business Data Catalog. Use valid names.

Project References

Add the following Project References in your console application code project before running this sample:

  • 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

Concepts

Business Data Catalog: Metadata Model

Other Resources

Browsing the Metadata Repository and Executing Methods and Filters
Building Custom Applications Using the Business Data Catalog