0 out of 1 rated this helpful - Rate this topic

ComplexType Class

Represents a complex type in a conceptual model.

Namespace:  System.Data.Metadata.Edm
Assembly:  System.Data.Entity (in System.Data.Entity.dll)
public class ComplexType : StructuralType

The ComplexType type exposes the following members.

  Name Description
Public property Abstract Gets a value indicating whether this type is abstract or not. (Inherited from EdmType.)
Public property BaseType Gets the base type of this type. (Inherited from EdmType.)
Public property BuiltInTypeKind Gets the built-in type kind for this ComplexType. (Overrides MetadataItem.BuiltInTypeKind.)
Public property Documentation Gets or sets the documentation associated with this type. (Inherited from MetadataItem.)
Public property FullName Gets the full name of this type. (Inherited from EdmType.)
Public property Members Gets the list of members on this type. (Inherited from StructuralType.)
Public property MetadataProperties Gets the list of properties of the current type. (Inherited from MetadataItem.)
Public property Name Gets the name of this type. (Inherited from EdmType.)
Public property NamespaceName Gets the namespace of this type. (Inherited from EdmType.)
Public property Properties Gets the list of properties for this ComplexType.
Top
  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetCollectionType Returns an instance of the CollectionType whose element type is this type. (Inherited from EdmType.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns the full name of this type. (Inherited from EdmType.)
Top

The ComplexType in a conceptual model represents a type that includes a set of properties like an entity type but does not include a key property. For more information about the complex types in a conceptual model, see Complex Type and How to: Define a Model with Complex Types (Entity Framework).

The following code sample gets a metadata workspace from the connection and uses that metadata workspace to retrieve information about the properties of the complex types in the specified model. 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 CustomerComplexAddr model that is provided in How to: Define a Model with Complex Types (Entity Framework) topic. For an example of the application config file, see Implementing Complex Type (EDM) topic.

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

.NET Framework

Supported in: 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ