GlobalItem Class

Represents the base item class for all the Entity Data Model (EDM) types and the entity containers.

Namespace:  System.Data.Metadata.Edm
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public abstract class GlobalItem : MetadataItem

For more information, see Metadata Type Hierarchy Overview.

The following code sample demonstrates how to get a metadata workspace from the connection and then use that metadata workspace to browse the metadata type hierarchy. Note that the metadata workspace is a runtime service component that provides support for retrieving metadata.

The code sample uses a CSpace and a SSpace to specify the model. The CSpace represents the default name for the conceptual model. The SSpace represents the default name for the storage model. The code sample uses the AdventureWorks model that is provided in the Adventure Works Model (EDM) topic. For an example of the application config file, see Adventure Works Object Model in Applications (EDM).

using System;
using System.Data;
using System.Data.EntityClient;
using System.Data.Metadata.Edm;
using System.Collections.ObjectModel;

class BrowseTypes
{
  static void Main()
  {
    try
    {
      // Establish a connection to the underlying data provider by
      // using the connection string specified in the config file.
      using (EntityConnection connection =
         new EntityConnection("Name=AdventureWorksEntities"))
      {
         // Open the connection.
         connection.Open();
         // Access the metadata workspace.
         MetadataWorkspace workspace = 
             connection.GetMetadataWorkspace();

         // Browse the metadata type hierarchy in the conceptual model.
         BrowseTypesExample(workspace, DataSpace.CSpace);

         // Browse the metadata type hierarchy in the storage model.
         BrowseTypesExample(workspace, DataSpace.SSpace);
      }
    }
    catch (MetadataException exceptionMetadata)
    {
      Console.WriteLine("MetadataException: {0}",
                      exceptionMetadata.Message);
    }
    catch (System.Data.MappingException exceptionMapping)
    {
      Console.WriteLine("MappingException: {0}",
                       exceptionMapping.Message);
    }
  }

  private static void BrowseTypesExample(MetadataWorkspace workspace, 
    DataSpace model)
  {
    // Get a collection of the GlobalItems. 
    // An GlobalItem class is the base class for 
    // the entity data model types and entity containers.
    ReadOnlyCollection<GlobalItem> items = 
         workspace.GetItems<GlobalItem>(model);

    // Iterate through the collection to get each item.
    foreach (GlobalItem item in items)
    {
       EntityContainer entityContainer = item as EntityContainer;
       if (entityContainer != null)
       {
         Console.WriteLine(
            "EntityContainer Name: {0}",
             entityContainer.Name);
                continue;
       }

       EntityType entityType = item as EntityType;
       if (entityType != null)
       {
          Console.WriteLine(
            "EntityType Name: {0}, Namespace: {1}",
             entityType.Name, entityType.NamespaceName);
          continue;
       }

       AssociationType associationType = item as AssociationType;
       if (associationType != null)
       {
          Console.WriteLine(
            "AssociationType Name: {0}, Namespace: {1}",
            associationType.Name, associationType.NamespaceName);
          continue;
        }

        PrimitiveType primType = item as PrimitiveType;
        if (primType != null)
        {
          Console.WriteLine(
            "PrimitiveType Name: {0}, Namespace: {1}", 
            primType.Name, primType.NamespaceName);
            continue;
        }

        EdmFunction function = item as EdmFunction;
        if (function != null)
        {
          Console.WriteLine(
            "Function Name: {0}, Namespace: {1}",
            function.Name, function.NamespaceName);
          continue;
        }
      }
  }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft