ComplexType 類別

定義

表示概念模型中的複雜型別。

public ref class ComplexType : System::Data::Metadata::Edm::StructuralType
public class ComplexType : System.Data.Metadata.Edm.StructuralType
type ComplexType = class
    inherit StructuralType
Public Class ComplexType
Inherits StructuralType
繼承

範例

下列程式代碼範例會從連接取得元數據工作區,並使用該元數據工作區來擷取指定模型中複雜類型屬性的相關信息。 請注意,中繼資料工作空間是一個執行階段服務元件,它會提供用來擷取中繼資料的支援。

此程式碼範例會使用 CSpace 來指定此模型。 CSpace 代表概念模型的預設名稱。 此程式代碼範例使用 How to: Define a Model with Complex Types (Entity Framework) 主題中提供的 CustomerComplexAddr 模型。

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

class GetComplexTypeMembersExample  
{  
  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=CustomerWComplexAddrEntities"))  
      {  
         // Open the connection.  
         connection.Open();  

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

         // Get properties of complex types.  
         GetProperties(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 GetProperties(MetadataWorkspace workspace,   
      DataSpace model)  
  {  
    // Get a collection of complex types.  
    ReadOnlyCollection<ComplexType> complexTypes =  
       workspace.GetItems<ComplexType>(model);  

    // Iterate through the collection to get each complex type.  
    foreach (ComplexType complexType in complexTypes)  
    {  
       Console.WriteLine(  
         "\n\n***ComplexType Name: {0}, Namespace: {1}",  
         complexType.Name,  
         complexType.NamespaceName);  

       Console.WriteLine(  
          "\nGet the properties of this " +  
          "ComplexType object ==>");  
          // Iterate through the collection to get each property of the   
          // current ComplexType object.  
          foreach (EdmProperty property in complexType.Properties)  
          {  
            Console.Write("   Property Name: {0} ", property.Name);  

            Console.WriteLine(  
               "   Property declaring Type: {0}, edmtype: {1}," +  
               " default: {2}, nullable: {3} ",  
               property.DeclaringType, property.TypeUsage.EdmType,  
               property.Default, property.Nullable);  
          }  
      }  
  }  
}  
Imports System  
Imports System.Collections.ObjectModel  
Imports System.Data  
Imports System.Data.EntityClient  
Imports System.Data.Metadata.Edm  

Class GetComplexTypeMembersExample  
  Public Shared Sub Main()  
    Try  
      ' Establish a connection to the underlying data provider by   
      ' using the connection string specified in the config file.  
      Using connection As EntityConnection = _  
         New EntityConnection("Name=CustomerWComplexAddrEntities")  

         ' Open the connection.  
         connection.Open()  

         ' Access the metadata workspace.  
         Dim workspace As MetadataWorkspace = _  
            connection.GetMetadataWorkspace  

         ' Get properties of complex types.  
         GetProperties(workspace, DataSpace.CSpace)  
      End Using  
    Catch exceptionMetadata As MetadataException  
       Console.WriteLine("MetadataException: {0}", _  
           exceptionMetadata.Message)  
    Catch exceptionMapping As MappingException  
       Console.WriteLine("MappingException: {0}", _  
           exceptionMapping.Message)  
     End Try  
  End Sub  

  Public Shared Sub GetProperties( _  
    ByVal workspace As MetadataWorkspace, ByVal model As DataSpace)  

    ' Get a collection of complex types.  
    Dim complexTypes As ReadOnlyCollection(Of ComplexType) = _  
       workspace.GetItems(Of ComplexType)(model)  

    ' Iterate through the collection to get each complex type.  
    Dim complexType As ComplexType  
    For Each complexType In complexTypes  
       Console.WriteLine( _  
          ControlChars.Lf & ControlChars.Lf & _  
          "***ComplexType Name: {0}, Namespace: {1}", _  
          complexType.Name, complexType.NamespaceName)  

       Console.WriteLine(ControlChars.Lf & _  
          "Get the properties of this ComplexType object ==>")  

          ' Iterate through the collection to get each property of the   
          ' current ComplexType object.  
          Dim property1 As EdmProperty  
          For Each property1 In complexType.Properties  
            Console.Write("   Property Name: {0} ", property1.Name)  
            Console.WriteLine( _  
              "   Property declaring Type: {0}, edmtype: {1}, " + _  
              "default: {2}, nullable: {3} ", _  
              New Object() {property1.DeclaringType, _  
              property1.TypeUsage.EdmType, _  
              property1.Default, property1.Nullable})  
          Next  
        Next  
    End Sub  
End Class  

備註

ComplexType概念模型中的 代表類型,其中包含一組屬性,例如實體類型,但不包含索引鍵屬性。 如需概念模型中複雜類型的詳細資訊,請參閱 複雜型 別和 如何:使用複雜類型定義模型 (Entity Framework)

屬性

Abstract

取得表示這個型別是否為抽象的值。

(繼承來源 EdmType)
BaseType

取得這個型別的基底類型 (Base Type)。

(繼承來源 EdmType)
BuiltInTypeKind

取得這個 ComplexType 的內建型別類型。

Documentation

取得或設定與這個型別相關聯的文件。

(繼承來源 MetadataItem)
FullName

取得這個型別的完整名稱。

(繼承來源 EdmType)
Members

取得這個型別的屬性清單。

(繼承來源 StructuralType)
MetadataProperties

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

(繼承來源 MetadataItem)
Name

取得這個型別的名稱。

(繼承來源 EdmType)
NamespaceName

取得這個型別的命名空間 (Namespace)。

(繼承來源 EdmType)
Properties

取得這個 ComplexType 的屬性清單。

方法

Equals(Object)

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

(繼承來源 Object)
GetCollectionType()

傳回 CollectionType 的執行個體 (Instance),其項目型別為這個型別。

(繼承來源 EdmType)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回這個型別的完整名稱。

(繼承來源 EdmType)

適用於