語言

GlobalItem 類別

定義

代表所有概念模型類型與實體容器的基底項目類別。

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
繼承
GlobalItem
衍生

範例

以下程式碼範例示範如何從連線取得一個中繼資料工作區,然後利用該中繼資料工作區瀏覽中繼資料類型階層。 請注意,元資料工作區是一個執行時服務元件,提供支援元資料擷取的支援。

程式碼範例使用 a CSpace 來指定模型。 代表 CSpace 概念模型的預設名稱。 範例程式碼使用應用程式設定檔中提供的 連接字串。

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

屬性

名稱 Description
BuiltInTypeKind

這類型有內建的類型。

(繼承來源 MetadataItem)
Documentation

取得或設定與此類型相關的文件。

(繼承來源 MetadataItem)
MetadataProperties

取得目前類型的屬性清單。

(繼承來源 MetadataItem)

方法

名稱 Description
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於