次の方法で共有


NavigationProperty 要素 (CSDL)

NavigationProperty 要素は、ナビゲーション プロパティを定義します。このプロパティは、アソシエーションの他方の End を参照できるようにします。 Property 要素で定義されるプロパティとは異なり、ナビゲーション プロパティはデータの形と特性を定義しません。 ナビゲーション プロパティは、アソシエーション内で 2 つのエンティティ型間を移動するための手段を提供します。

Note that navigation properties are optional on both entity types at the ends of an association. 1 つのアソシエーション End のエンティティ型にナビゲーション プロパティを定義した場合に、そのアソシエーションの他方の End でもエンティティ型にナビゲーション プロパティを定義する必要はありません。

ナビゲーション プロパティによって返されるデータ型は、リモートのアソシエーション End の多重度により決まります。 たとえば、ナビゲーション プロパティ OrdersNavPropCustomer エンティティ型に存在し、CustomerOrder の間の一対多のアソシエーションで移動するとします。 ナビゲーション プロパティのリモートのアソシエーション End の多重度が多数 (*) であるため、そのデータ型はコレクション (Order の) になります。 同様に、Order エンティティ型にナビゲーション プロパティ CustomerNavProp が存在する場合、リモート End の多重度が (1) であるため、データ型は Customer になります。

A NavigationProperty element can have the following child elements (in the order listed):

適用可能な属性

The table below describes the attributes that can be applied to the NavigationProperty element.

属性名 必須 Value

Name

有効

ナビゲーション プロパティの名前。

Relationship

有効

モデルのスコープ内にあるアソシエーションの名前。

ToRole

有効

ナビゲーションが終了する側のアソシエーション End。 The value of the ToRole attribute must be the same as the value of one of the Role attributes defined on one of the association ends (defined in the AssociationEnd element).

FromRole

有効

ナビゲーションが始まる側のアソシエーション End。 The value of the FromRole attribute must be the same as the value of one of the Role attributes defined on one of the association ends (defined in the AssociationEnd element).

Bb387104.note(ja-jp,VS.100).gif注 :
NavigationProperty 要素には、任意の数の annotation 属性 (カスタム XML 属性) を適用できます。However, custom attributes may not belong to any XML namespace that is reserved for CSDL.カスタム属性の完全修飾名は一意である必要があります。

次の例は、2 つのナビゲーション プロパティ (PublishedByWrittenBy) を持つエンティティ型 (Book) を定義します。

<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>

参照

概念

エンティティ フレームワークの概要
CSDL 仕様
Schema 要素 (CSDL)

その他のリソース

CSDL、SSDL、および MSL 仕様
ADO.NET Entity Data Model Tools
navigation property (Entity Data Model)