PropertyKind 枚举

定义

指定概念模型中项特性的类型。Specifies the kinds of item attributes in the conceptual model.

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

字段

Extended 1

一个指示项属性为 Extended 的枚举成员。An enumeration member indicating that an item attribute is Extended.

System 0

一个指示项属性为 System 的枚举成员。An enumeration member indicating that an item attribute is System.

示例

下面的代码示例演示如何利用连接获取元数据工作区,然后使用该元数据工作区在指定的数据模型中检索有关扩展属性的信息。The following code sample demonstrates how to get a metadata workspace from the connection and then use that metadata workspace to retrieve information about the extended properties in the specified data model. 请注意,元数据工作区是一个为检索元数据提供支持的运行时服务组件。Note that the metadata workspace is a runtime service component that provides support for retrieving metadata.

该代码示例使用 CSpace 指定模型。The code sample uses a CSpace to specify the model. CSpace 表示概念性模型的默认名称。The CSpace represents the default name for the conceptual model. 此代码示例使用Adventureworks 模型 (EDM)主题中提供的 adventureworks 模型。The code sample uses the AdventureWorks Model that is provided in the AdventureWorks Model (EDM) topic. 有关应用程序配置文件的示例, 请参阅应用程序中的 AdventureWorks 对象模型 (EDM)For an example of the application config file, see AdventureWorks Object Model in Applications (EDM).

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

注解

有关详细信息, 请参阅扩展属性 (CSDL)For more information, see Extended Property (CSDL).

适用于