AssociationSet 元素 (EntityContainer SSDL)
在 实体数据模型 (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 完整模型 (EDM)