2.1.2 EntityType

An entity is an instance of an EntityType element. An EntityType has a unique identity, an independent existence, and forms the operational unit of consistency. EntityType elements model the top-level concepts within a data model--such as customers, orders, suppliers, and so on (to take the example of a typical line-of-business system). An entity instance represents one particular instance of the EntityType, such as a specific customer or a specific order. An EntityType can be either abstract or concrete. An abstract EntityType cannot be instantiated.

An EntityType has a Name attribute, a payload consisting of one or more declared properties, and an entity Key (section 2.1.5) element that specifies the set of properties whose values uniquely identify an entity within an entity set. An EntityType can have one or more properties of the specified scalar type or ComplexType. A property can be a declared property or a dynamic property.

In CSDL 1.2, CSDL 2.0, and CSDL 3.0, an EntityType can be an OpenEntityType. An EntityType is indicated to be an OpenEntityType by the presence of an OpenType="true" attribute. If an EntityType is an OpenEntityType, the set of properties that are associated with the EntityType can, in addition to declared properties, include dynamic properties.

Note In CSDL, dynamic properties are defined for use only with OpenEntityType instances.

The type of a Property in an EntityType can be a scalar type or ComplexType. EntityType can be categorized as an EDM type.

The following is an example of an EntityType.

   <EntityType Name="Customer">
     <Key>
       <PropertyRef Name="CustomerId" />
     </Key>
     <Property Name="CustomerId" Type="Int32" Nullable="false" />
     <Property Name="FirstName" Type="String" Nullable="true" />
     <Property Name="LastName" Type="String" Nullable="true" />
     <Property Name="AccountNumber" Type="Int32" Nullable="true" />
     <NavigationProperty Name="Orders" Relationship="Model1.CustomerOrder" FromRole="Customer" ToRole="Order" />
   </EntityType>

The following rules apply to the EntityType element:

  • EntityType MUST have a Name attribute defined. The Name attribute is of type SimpleIdentifier and represents the name of this EntityType.

  • An EntityType is a schema level named element and has a unique name.

  • EntityType can derive from a BaseType, which is used to specify the parent type of a derived type. The derived type inherits properties from the parent type.

  • If a BaseType is defined, it has a namespace qualified name or an alias qualified name of an EntityType that is in scope.

  • An EntityType cannot introduce an inheritance cycle via the BaseType attribute.

  • An EntityType can have its Abstract attribute set to "true". By default, the Abstract attribute is set to "false".

  • An EntityType can contain any number of AnnotationAttribute attributes, but their full names cannot collide.

  • An EntityType element can contain at most one Documentation element.

  • An EntityType either defines an entity Key element or derive from a BaseType. Derived EntityType elements cannot define an entity Key. A key forms the identity of the Entity.

  • An EntityType can have any number of Property and NavigationProperty elements in any given order.

  • EntityTypeProperty child elements are uniquely named within the inheritance hierarchy for the EntityType. Property child elements and NavigationProperty child elements cannot have the same name as their declaring EntityType.

  • An EntityType can contain any number of AnnotationElement element blocks.

  • In CSDL 1.2, CSDL 2.0, and CSDL 3.0, an EntityType that represents an OpenEntityType MUST have an OpenType attribute that is defined with its value equal to "true".

  • In CSDL 1.2, CSDL 2.0, and CSDL 3.0, an EntityType that derives from an OpenEntityType is itself an OpenEntityType. Such a derived EntityType cannot have an OpenType attribute with its value equal to "false", but the derived EntityType can have an OpenType attribute defined with its value equal to "true".

  • In CSDL 3.0, EntityType can contain any number of TypeAnnotation elements.

  • In CSDL 3.0, EntityType can contain any number of ValueAnnotation elements.

Graphic representation in table format of the rules that apply to the EntityType element.

All child elements are to appear in the order indicated. For all child elements within a given choice, the child elements can be ordered arbitrarily.

Show: