Entity Type (EDM)
In the Entity Data Model (EDM), an EntityType is the design template for a data type in the application domain. An entity declaration schematically represents a particular type of data. The schema is used, unencumbered by table structure or code, to specify all details of the data type. After the design is complete, a programmable data type is built based on the design.
An EDM EntityType is used to model a top-level concept, such as a customer, an order, or a supplier in a business application. Each entity is defined as an EntityType in conceptual schema definition language (CSDL). After the EntityType has been defined schematically, it becomes an operational unit for application development. Each EntityType is conceptually independent and has unique identity.
Entity Properties and Identity
An EntityType in a schema has a name, properties, and a Key property that identifies the data type when it is instantiated by application code.
Most of the information about an EntityType is contained by its properties. A property is data of an EDM SimpleType or ComplexType. Properties are single-valued, although a NavigationProperty type can be used with an Association to implement a property that works like a collection of data items. For more information about navigation properties, see Navigation Properties (EDM) in the EDM. For more information about associations, see Entity Data Model Relationships.
A property adds information to an EntityType by defining a unique name for a value of a specified data type. The property specification consists of a name and type and can specify access constraints using the GetterAccess and SetterAccess attributes. The type of a property is selected from those specified as EDM SimpleType.
The value of all properties except those participating in a Key can be Null. The following example shows the declaration of an EntityType.
<EntityType Name="Person"> <Key> <PropertyRef Name="EmailID"/> </Key> <Property Name="EmailID" Type="String" Nullable="false" /> <Property Name="Name" Type="String" /> <Property Name="Address" Type="String" /> <Property Name="PhoneNumber" Type=" String"/> </EntityType>
In this example, the
EmailID property is specified as the Key property in this entity. The key cannot be
Null, that is, a Person instance must have an e-mail identifier. The Key is used to identify instances of the type in applications that use it.
An EntityType must define a Key that consists of one or more of the properties defined for that type. Any set of SimpleType properties can serve as the Key. None of the properties used in the Key can be
Null in application code.
Using a String type as the Key is not a good practice for reasons of both performance and predictability; the meaning of str1 == str2 is highly ambiguous.
<EntityType Name="Person"> <Key> <PropertyRef Name="ContactId" /> <PropertyRef Name="Name" /> </Key> <Property Name="ContactId" Type="String" Nullable="false" /> <Property Name="Name" Type="String" Nullable="false" /> <Property Name="PhoneNumber" Type="String" /> </EntityType>