다음을 통해 공유


Code Snippet: Get the DatabaseBackedMetadataCatalog on the Server

Applies to: SharePoint Server 2010

In this article
Description
Prerequisites
To use this example

Description

The following code example shows how to get the DatabaseBackedMetadataCatalog on the server by using the Business Data Connectivity (BDC) service Runtime object model on the server.

Prerequisites

  • Microsoft SharePoint Server 2010 or Microsoft SharePoint Foundation 2010 installed on the server

  • Microsoft .NET Framework 3.5 and Microsoft Visual Studio

  • At least one external content type registered in the BDC Metadata Store

To use this example

  1. Start Visual Studio, and then create a new C# Console application project. Select .NET Framework 3.5 when you create the project.

  2. From the View menu, select Property Pages to bring up the project properties.

  3. On the Build tab, for the Platform target, select Any CPU.

  4. Close the project properties window.

  5. In Solution Explorer, under References, remove all project references except for System and System.Core.

  6. Add the following references to the project:

    1. Microsoft.BusinessData (from SharePoint_RootFolder\ISAPI)

    2. Microsoft.SharePoint

  7. Replace the auto-generated code in Program.cs with the code listed at the end of this procedure.

  8. Replace the placehoder values of <siteUrl>, <nameSpace>, <lobsystemInstance>, and <entityName> with valid values.

  9. Save the project.

  10. Compile the project.

  11. Run the application on the server computer where SharePoint Server 2010 or SharePoint Foundation 2010 is installed.

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];

See Also

Reference

IMetadataCatalog

BdcService

GetDatabaseBackedMetadataCatalog(SPServiceContext)

GetEntity(String, String)

IEntity

GetLobSystem()

ILobSystem

GetLobSystemInstances()

ILobSystemInstance