エンティティ データ モデル (EDM) では、ストレージ メタデータのアソシエーションはストア スキーマ定義言語 (SSDL) の AssociationSet 要素によって指定されます。
概念スキーマから構築されるオブジェクト モデルには、そのモデルに基づいて構築されたアプリケーションのデータを格納するために、プログラミング可能なクラスとストレージ構造の両方が必要です。マッピング スキーマ言語 (MSL) の AssociationSetMapping は、概念スキーマ定義言語 (CSDL) で定義された AssociationSet を、ストレージ構造が記述された SSDL の AssociationSet に関連付けます。
次の CSDL 構文では、AdventureWorks.Store スキーマの FK_Employee_Employee_ManagerID という名前の AssociationSet を宣言しています。この AssociationSet は、AdventureWorks メタデータの AdventureWorks.Store という名前の EntityContainer の一部です。この EntityContainer は AdventureWorks.Store スキーマで定義されていますが、EntityContainer は独立した要素です。
AssociationSet 要素は Name を割り当て、このアソシエーション セットの指定で使用される AssociationType を識別します。
<EntityContainer Name="Adventureworks.Store">
<AssociationSet Name="FK_Employee_Employee_ManagerID"
Association="Adventureworks.Store.FK_Employee_Employee_ManagerID">
<End Role="Employee" EntitySet="Employee" />
<End Role="Employee1" EntitySet="Employee" />
</AssociationSet>
</EntityContainer>
<Association Name="FK_Employee_Employee_ManagerID">
<End Role="Employee" Type="Adventureworks.Store.Employee" Multiplicity="0..1" />
<End Role="Employee1" Type="Adventureworks.Store.Employee" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Employee">
<PropertyRef Name="EmployeeID" />
</Principal>
<Dependent Role="Employee1">
<PropertyRef Name="ManagerID" />
</Dependent>
</ReferentialConstraint>
</Association>
この例では、ReferentialConstraint 要素は、アソシエーションがデータベースの構造に依存していることを示します。ReferentialConstraint は、Principal Role と Dependent Role を指定し、最も重要なものとして、データベース内の外部キー リレーションシップに対応する各ロールの PropertyRef を指定します。
Principal Role の PropertyRef は、Employee データベース テーブルの外部キー列に割り当てられるプロパティを指定します。Dependent Role の PropertyRef は、外部キーを格納する列を指定します。たとえば、FK_Employee_Employee_ManagerID アソシエーションでは、Dependent Role の PropertyRef は、Employee テーブルの外部キー列 ManagerID に格納されているマネージャである従業員の EmployeeID プロパティです。ReferentialConstraint を使用する完全な例については、「アソシエーションの実装 (EDM)」を参照してください。
プログラミング オブジェクト モデルの構築時、FK_Employee_Employee_ManagerID 型のエンティティはアプリケーション コードによってインスタンス化できます。
完全を期すために、AssociationType は、EntityContainer と AssociationSet の定義の後に宣言します。
参照
概念
AssociationSet 要素 (EntityContainer CSDL)
EntitySetMapping 要素 (MSL)
エンティティ セット (EDM)
アソシエーション セット (EDM)
AdventureWorks Complete Model (EDM)