Association 元素 (SSDL)
以存储架构定义语言 (SSDL) 表示的 Association 元素指定参与基础数据库中的外键约束的表列。 两个必需的子 End 元素指定位于关联两端的表和各端的重数。 一个可选的 ReferentialConstraint 元素指定关联的主体端和依赖端以及参与列。 如果不存在 ReferentialConstraint 元素,则必须使用一个 AssociationSetMapping 元素指定关联的列映射。
Association 元素可以具有以下子元素(按所列顺序):
Documentation(零个或一个)
End(正好两个)
ReferentialConstraint(零个或一个)
批注元素(零个或多个)
适用的特性
下表介绍可应用于 Association 元素的特性。
特性名称 | 是否必需 | 值 |
---|---|---|
Name |
是 |
基础数据库中相应外键约束的名称。 |
注意: |
---|
可以将任何数量的批注特性(自定义 XML 特性)应用于 Association 元素。然而,自定义特性可能不属于为 SSDL 保留的任何 XML 命名空间。任何两个自定义特性的完全限定名称都不能相同。 |
示例
下面的示例显示一个 Association 元素,该元素使用 ReferentialConstraint 元素指定参与 FK_CustomerOrders 外键约束的列:
<Association Name="FK_CustomerOrders">
<End Role="Customers"
Type="ExampleModel.Store.Customers" Multiplicity="1">
<OnDelete Action="Cascade" />
</End>
<End Role="Orders"
Type="ExampleModel.Store.Orders" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Customers">
<PropertyRef Name="CustomerId" />
</Principal>
<Dependent Role="Orders">
<PropertyRef Name="CustomerId" />
</Dependent>
</ReferentialConstraint>
</Association>
另请参见
概念
实体框架概述
SSDL 规范
AssociationSet 元素 (SSDL)