共用方式為


AssociationSet 項目 (EntityContainer SSDL)

在 實體資料模型 (EDM) 中,存放結構定義語言 (SSDL) 中的 AssociationSet 項目會指定儲存中繼資料內的關聯。

從概念結構描述建置而來的物件模型同時需要可程式化類別和儲存結構,以容納模型上所建置之應用程式的資料。對應規格語言 (MSL) 中的 AssociationSetMapping 會將概念結構定義語言 (CSDL) 中定義的 AssociationSet 連接到描述儲存結構之 SSDL 中的 AssociationSet

下列 CSDL 語法顯示 AdventureWorks.Store 結構描述中名為 FK_Employee_Employee_ManagerIDAssociationSet 的宣告。這個 AssociationSet 是 AdventureWorks 中繼資料內名為 AdventureWorks.StoreEntityContainer 的一部分。雖然這個 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 RoleDependent Role 及最重要的 PropertyRef

Principal RolePropertyRef 會指定指派給 Employee 資料庫資料表之外部索引鍵資料行的屬性。Dependent RolePropertyRef 會指定保存此外部索引鍵的資料行。例如在 FK_Employee_Employee_ManagerID 關聯中, Dependent RolePropertyRef 是經理員工的 EmployeeID 屬性 (該屬性是由 Employee 資料表的 ManagerID 外部索引鍵資料行所容納)。如需使用 ReferentialConstraint 的完整範例,請參閱實作關聯 (EDM)

當建置程式設計物件模型時,可以在應用程式程式碼中具現化 FK_Employee_Employee_ManagerID 類型的實體。

基於完整性,此範例中的 AssociationType 宣告會包含在 EntityContainerAssociationSet 定義的後面。

另請參閱

概念

AssociationSet 項目 (EntityContainer CSDL)
EntitySetMapping 項目 (MSL)
實體集 (EDM)
關聯集 (EDM)
AdventureWorks 完整模型 (EDM)