Partilhar via


navigation property (Entity Data Model)

A navigation property is an optional property on an entity type that allows for navigation from one end of an association to the other end. Unlike other properties, navigation properties do not carry data.

A navigation property definition includes the following:

  • A name. (Required)

  • The association that it navigates. (Required)

  • The ends of the association that it navigates. (Required)

Note that navigation properties are optional on both entity types at the ends of an association. If you define a navigation property on one entity type at the end of an association, you do not have to define a navigation property on the entity type at the other end of the association.

The data type of a navigation property is determined by the multiplicity of its remote association end. For example, suppose a navigation property, OrdersNavProp, exists on a Customer entity type and navigates a one-to-many association between Customer and Order. Because the remote association end for the navigation property has multiplicity of many (*), its data type is a collection (of Order). Similarly, if a navigation property, CustomerNavProp, exists on the Order entity type, its data type would be Customer, because the multiplicity of the remote end is one (1).

Example

The diagram below shows a conceptual model with three entity types: Book, Publisher, and Author. Navigation properties, Publisher and Authors, are defined on the Book entity type. Navigation property Books is defined on both the Publisher entity type and the Author entity type.

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

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>

Note that XML attributes are used to communicate the information necessary to define a navigation property: The attribute Name contains the name of the property, Relationship contains the name of the association it navigates, and FromRole and ToRole contain the ends of the association.

See Also

Concepts

Entity Data Model Key Concepts

Entity Data Model