entity type
The entity type is the fundamental building block for describing the structure of data with the Entity Data Model (EDM). In a conceptual model, an entity type represents the structure of top-level concepts, such as customers or orders. An entity type is a template for entity type instances. Each template contains the following information:
A unique name. (Required.)
An entity key defined by one or more properties. (Required.)
Data in the form of properties. (Optional.)
Navigation properties that allow for navigation from one end of an association to the other end. (Optional)
In an application, an instance of an entity type represents a specific object (such as a specific customer or order). Each instance of an entity type must have a unique entity key within an entity set.
Two entity type instances are considered equal only if they are of the same type and the values of their entity keys are the same.
Example
The diagram below shows a conceptual model with three entity types: Book
, Publisher
, and Author
:
Note that the properties of each entity type that make up its entity key are denoted with "(Key)".
The ADO.NET Entity Framework uses a domain-specific language (DSL) called conceptual schema definition language (CSDL) to define conceptual models. The following CSDL defines the Book
entity type shown in the diagram above:
<EntityType Name="Book">
<Key>
<PropertyRef Name="ISBN" />
</Key>
<Property Type="String" Name="ISBN" Nullable="false" />
<Property Type="String" Name="Title" Nullable="false" />
<Property Type="Decimal" Name="Revision" Nullable="false" Precision="29" Scale="29" />
<NavigationProperty Name="Publisher" Relationship="BooksModel.PublishedBy"
FromRole="Book" ToRole="Publisher" />
<NavigationProperty Name="Authors" Relationship="BooksModel.WrittenBy"
FromRole="Book" ToRole="Author" />
</EntityType>