Share via

ComplexType Element (CSDL)

A ComplexType element defines a data structure composed of EdmSimpleType properties or other complex types. For more information about the EdmSimpleType, see Conceptual Model Types (CSDL). A complex type can be a property of an entity type or another complex type. A complex type is similar to an entity type in that a complex type defines data. However, there are some key differences between complex types and entity types:

  • Complex types do not have identities (or keys) and therefore cannot exist independently. Complex types can only exist as properties of entity types or other complex types.

  • Complex types cannot participate in associations. Neither end of an association can be a complex type, and therefore navigation properties cannot be defined for complex types.

  • A complex type property cannot have a null value, though the scalar properties of a complex type may each be set to null.

A ComplexType element can have the following child elements (in the order listed):

The table below describes the attributes that can be applied to the ComplexType element.

Attribute Name Is Required Value



The name of the complex type. The name of a complex type cannot be the same as the name of another complex type, entity type, or association that is within the scope of the model.



The name of another complex type that is the base type of the complex type that is being defined.

This attribute is not applicable in the CSDL version specified by the namespace Inheritance for complex types is not supported in that version.



True or False (the default value) depending on whether the complex type is an abstract type.

This attribute is not applicable in the CSDL version specified by the namespace Complex types in that version cannot be abstract types.


Any number of annotation attributes (custom XML attributes) may be applied to the ComplexType element. However, custom attributes may not belong to any XML namespace that is reserved for CSDL. The fully-qualified names for any two custom attributes cannot be the same.


The following example shows a complex type, Address, with the EdmSimpleType properties StreetAddress, City, StateOrProvince, Country, and PostalCode.

<ComplexType Name="Address" >
  <Property Type="String" Name="StreetAddress" Nullable="false" />
  <Property Type="String" Name="City" Nullable="false" />
  <Property Type="String" Name="StateOrProvince" Nullable="false" />
  <Property Type="String" Name="Country" Nullable="false" />
  <Property Type="String" Name="PostalCode" Nullable="false" />

To define the complex type Address (above) as a property of an entity type, you must declare the property type in the entity type definition. The following example shows the Address property as a complex type on an entity type (Publisher):

<EntityType Name="Publisher">
        <PropertyRef Name="Id" />
      <Property Type="Int32" Name="Id" Nullable="false" />
      <Property Type="String" Name="Name" Nullable="false" />
      <Property Type="BooksModel.Address" Name="Address" Nullable="false" />
      <NavigationProperty Name="Books" Relationship="BooksModel.PublishedBy"
                          FromRole="Publisher" ToRole="Book" />

See Also


Entity Framework Overview
CSDL Specification
Schema Element (CSDL)
EntityType Element (CSDL)
Complex Type Objects

Other Resources

CSDL, SSDL, and MSL Specifications
ADO.NET Entity Data Model Tools
complex type (Entity Data Model)