共用方式為


PropertyKind 列舉

定義

指定概念模型中的項目屬性類型。

public enum class PropertyKind
public enum PropertyKind
type PropertyKind = 
Public Enum PropertyKind
繼承
PropertyKind

欄位

Extended 1

列舉成員,指出項目屬性為 Extended

System 0

列舉成員,指出項目屬性為 System

範例

下列程式碼範例會示範如何從連接中取得中繼資料工作空間,然後使用該中繼資料工作空間來擷取指定之模型內有關擴充屬性的資訊。 請注意,中繼資料工作空間是一個執行階段服務元件,它會提供用來擷取中繼資料的支援。

此程式碼範例會使用 CSpace 來指定此模型。 CSpace 代表概念模型的預設名稱。 程序代碼範例會使用 AdventureWorks 模型

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

class UsePropertyKindExample  
{  
   static void Main(string[] args)  
   {  
     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"))  
       {  
          // Open the connection.  
          connection.Open();  

          // Access the metadata workspace.  
          MetadataWorkspace workspace =   
             connection.GetMetadataWorkspace();  

          // Display the extended properties in the conceptual model.  
          DisplayProperties(workspace, DataSpace.CSpace);  
       }  
     }  
     catch (MetadataException exceptionMetadata)  
     {  
         Console.WriteLine("MetadataException: {0}",  
                         exceptionMetadata.Message);  
     }  
     catch (System.Data.MappingException exceptionMapping)  
     {  
         Console.WriteLine("MappingException: {0}",  
                          exceptionMapping.Message);  
     }  
   }  

   public static void DisplayProperties(  
        MetadataWorkspace workspace, DataSpace model)  
   {  
      // Get a collection of the entity containers.  
      ReadOnlyCollection<EntityContainer> containers =  
          workspace.GetItems<EntityContainer>(model);  

      // Iterate through the collection to get each entity container.  
      foreach (EntityContainer container in containers)  
      {  
          // Display the extended properties for the entity container.  
          DisplayExtendedProperties(container);  

          // Iterate through the collection to get each entity set.  
          foreach (EntitySetBase baseSet in container.BaseEntitySets)  
          {  
              // Check whether this instance is an EntitySet.  
              if (baseSet is EntitySet)  
              {  
                 // Display the extended properties for the entity set.  
                 DisplayExtendedProperties(baseSet);  
              }  
          }  
      }  

      // Get a collection of the entity types.  
      ReadOnlyCollection<EntityType> entities =   
             workspace.GetItems<EntityType>(model);  

      // Iterate through the collection to get each entity type.  
      foreach (EntityType entity in entities)  
      {  
         // Display the extended properties for the entity type.  
         DisplayExtendedProperties(entity);  
      }  
   }  

   private static void DisplayExtendedProperties(MetadataItem item)  
   {  
     foreach (MetadataProperty property in item.MetadataProperties)  
     {  
         if (property.PropertyKind == PropertyKind.Extended)  
           Console.WriteLine(string.Format("\t{0}\t{1}\t{2}",   
             item.GetType().Name, property.Name, property.Value));  
     }  
   }  
}  

適用於