Partilhar via


Entity Data Model Key Concepts

The Entity Data Model (EDM) uses three key concepts to describe the structure of data: entity type, association type, and property. These are the most important concepts in describing the structure of data in any implementation of the EDM.

Entity Type

The entity type is the fundamental building block for describing the structure of data with the Entity Data Model. In a conceptual model, entity types are constructed from properties and describe the structure of top-level concepts, such as a customers and orders in a business application. In the same way that a class definition in a computer program is a template for instances of the class, an entity type is a template for entities. An entity represents a specific object (such as a specific customer or order). Each entity must have a unique entity key within an entity set. An entity set is a collection of instances of a specific entity type. Entity sets (and association sets) are logically grouped in an entity container.

Inheritance is supported with entity types: that is, one entity type can be derived from another. For more information, see Entity Data Model: Inheritance.

Association Type

An association type (also called an association) is the fundamental building block for describing relationships in the Entity Data Model. In a conceptual model, an association represents a relationship between two entity types (such as Customer and Order). Every association has two association ends that specify the entity types involved in the association. Each association end also specifies an association end multiplicity that indicates the number of entities that can be at that end of the association. An association end multiplicity can have a value of one (1), zero or one (0..1), or many (*). Entities at one end of an association can be accessed through navigation properties, or through foreign keys if they are exposed on an entity type. For more information, see foreign key property (Entity Data Model).

In an application, an instance of an association represents a specific association (such as an association between an instance of Customer and instances of Order). Association instances are logically grouped in an association set. Association sets (and entity sets) are logically grouped in an entity container.

Property

Entity types contain properties that define their structure and characteristics. For example, a Customer entity type may have properties such as CustomerId, Name, and Address.

Properties in a conceptual model are analogous to properties defined on a class in a computer program. In the same way that properties on a class define the shape of the class and carry information about objects, properties in a conceptual model define the shape of an entity type and carry information about entity type instances.

A property can contain primitive data (such as a string, an integer, or a Boolean value), or structured data (such as a complex type). For more information, see Entity Data Model: Primitive Data Types.

Representations of a Conceptual Model

A conceptual model is a specific representation of the structure of some data as entities and relationships. One way to represent a conceptual model is with a diagram. The following diagram represents a conceptual model with three entity types (Book, Publisher, and Author) and two associations (PublishedBy and WrittenBy):

Ee382840.ModelWithNavProps(en-us,VS.100).gif

This representation, however, has some shortcomings when it comes to conveying some details about the model. For example, property type and entity set information are not conveyed in the diagram. The richness of a conceptual model can be conveyed more clearly with a domain-specific language (DSL). The ADO.NET Entity Framework uses an XML-based DSL called conceptual schema definition language (CSDL) to define conceptual models. The following is the CSDL definition of the conceptual model in the diagram above:

      <Schema xmlns="https://schemas.microsoft.com/ado/2008/09/edm"
              xmlns:cg="https://schemas.microsoft.com/ado/2006/04/codegeneration"
              xmlns:store="https://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"
              Namespace="BooksModel" Alias="Self">
        <EntityContainer Name="BooksContainer" >
          <EntitySet Name="Books" EntityType="BooksModel.Book" />
          <EntitySet Name="Publishers" EntityType="BooksModel.Publisher" />
          <EntitySet Name="Authors" EntityType="BooksModel.Author" />
          <AssociationSet Name="PublishedBy" Association="BooksModel.PublishedBy">
            <End Role="Book" EntitySet="Books" />
            <End Role="Publisher" EntitySet="Publishers" />
          </AssociationSet>
          <AssociationSet Name="WrittenBy" Association="BooksModel.WrittenBy">
            <End Role="Book" EntitySet="Books" />
            <End Role="Author" EntitySet="Authors" />
          </AssociationSet>
        </EntityContainer>
        <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>
        <EntityType Name="Publisher">
          <Key>
            <PropertyRef Name="Id" />
          </Key>
          <Property Type="Int32" Name="Id" Nullable="false" />
          <Property Type="String" Name="Name" Nullable="false" />
          <Property Type="String" Name="Address" Nullable="false" />
          <NavigationProperty Name="Books" Relationship="BooksModel.PublishedBy"
                              FromRole="Publisher" ToRole="Book" />
        </EntityType>
        <EntityType Name="Author">
          <Key>
            <PropertyRef Name="Name" />
            <PropertyRef Name="Address" />
          </Key>
          <Property Type="String" Name="Name" Nullable="false" />
          <Property Type="String" Name="Address" Nullable="false" />
          <NavigationProperty Name="Books" Relationship="BooksModel.WrittenBy"
                              FromRole="Author" ToRole="Book" />
        </EntityType>
    <Association Name="PublishedBy">
          <End Type="BooksModel.Book" Role="Book" Multiplicity="*" />
          <End Type="BooksModel.Publisher" Role="Publisher" Multiplicity="1" />
        </Association>
        <Association Name="WrittenBy">
          <End Type="BooksModel.Book" Role="Book" Multiplicity="*" />
          <End Type="BooksModel.Author" Role="Author" Multiplicity="*" />
        </Association>
      </Schema>

See Also

Concepts

Entity Data Model