แก้ไข

แชร์ผ่าน


GlobalItem Class

Definition

Represents the base item class for all the conceptual model types and entity containers.

public ref class GlobalItem abstract : System::Data::Metadata::Edm::MetadataItem
public abstract class GlobalItem : System.Data.Metadata.Edm.MetadataItem
type GlobalItem = class
    inherit MetadataItem
Public MustInherit Class GlobalItem
Inherits MetadataItem
Inheritance
GlobalItem
Derived

Examples

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 to specify the model. The CSpace represents the default name for the conceptual model. The code sample uses the connection string that's provided in the application config file.

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=AdventureworksContext"))  
      {  
         // Access the metadata workspace.  
         MetadataWorkspace workspace =   
              connection.GetMetadataWorkspace();  
         // Browse the metadata type hierarchy.  
         BrowseTypesExample(workspace);  
      }  
    }  
    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)  
  {  
    // Get a collection of the GlobalItems.   
    // An GlobalItem class is the base class for   
    // the conceptual model types and entity containers.  
    ReadOnlyCollection<GlobalItem> items =   
         workspace.GetItems<GlobalItem>(DataSpace.CSpace);  

    // Iterate through the collection to get each item.  
    foreach (GlobalItem item in items)  
    {  
       Console.WriteLine(  
           "Item BuiltInTypeKind: {0}, Type: {1} ",   
           item.BuiltInTypeKind, item.GetType().FullName);  

       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(  
           "EdmFunction Name: {0}, Namespace: {1}",  
           function.Name, function.NamespaceName);  
         continue;  
       }  
    }  
  }  
}  

Properties

BuiltInTypeKind

Gets the built-in type kind for this type.

(Inherited from MetadataItem)
Documentation

Gets or sets the documentation associated with this type.

(Inherited from MetadataItem)
MetadataProperties

Gets the list of properties of the current type.

(Inherited from MetadataItem)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to