End 元素 (SSDL)
以存储架构定义语言 (SSDL) 表示的 End 元素指定处于基础数据库中外键约束一端的表和行数。 End 元素可以是 Association 元素或 AssociationSet 元素的子元素。 在每种情况下,可能的子元素以及适用的特性都不同。
End 元素作为 Association 元素的子元素
End 元素(作为 Association 元素的子元素)分别使用 Type 和 Multiplicity 特性指定处于外键约束一端的表和行数。 外键约束的两端定义为 SSDL 关联的一部分;SSDL 关联必须仅具有两端。
End 元素可以具有以下子元素(按所列顺序):
Documentation(零个或一个元素)
OnDelete(零个或一个元素)
批注元素(零个或多个元素)
适用的特性
下表介绍可应用于 End 元素(如果该元素是 Association 元素的子元素)的特性。
特性名称 | 是否必需 | 值 |
---|---|---|
Type |
是 |
处于外键约束端的 SSDL 实体集的完全限定名。 |
Role |
否 |
相应的 ReferentialConstraint 元素(如果使用)的 Principal 或 Dependent 元素中 Role 特性的值。 |
Multiplicity |
是 |
1、0..1 或 *,具体取决于外键约束端处可以存在的行数。
|
注意: |
---|
可以将任意数量的批注特性(自定义 XML 特性)应用于 End 元素。然而,自定义特性可能不属于为 CSDL 保留的任何 XML 命名空间。任何两个自定义特性的完全限定名称都不能相同。 |
示例
下面的示例显示用于定义 FK_CustomerOrders 外键约束的 Association 元素。 在每个 End 元素上指定的 Multiplicity 值指示可以将 Orders 表中的多行与 Customers 表中的一行关联,但只能将 Customers 表中的一行与 Orders 表中的一行关联。 此外,OnDelete 元素指示如果删除 Customers 表中的行,则也会删除 Orders 表中引用 Customers 表中该特定行的所有行。
<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>
End 元素作为 AssociationSet 元素的子元素
End 元素(作为 AssociationSet 元素的子元素)指定处于基础数据库中外键约束一端的表。
End 元素可以具有以下子元素(按所列顺序):
Documentation(零个或一个)
批注元素(零个或多个)
适用的特性
下表介绍可应用于 End 元素(如果该元素是 AssociationSet 元素的子元素)的特性。
特性名称 | 是否必需 | 值 |
---|---|---|
EntitySet |
是 |
处于外键约束一端的 SSDL 实体集的名称。 |
Role |
否 |
在相应的 Association 元素的一个 End 元素上指定的其中一个 Role 特性的值。 |
注意: |
---|
可以将任意数量的批注特性(自定义 XML 特性)应用于 End 元素。然而,自定义特性可能不属于为 CSDL 保留的任何 XML 命名空间。任何两个自定义特性的完全限定名称都不能相同。 |
示例
下面的示例演示一个 EntityContainer 元素,该元素中的一个 AssociationSet 元素具有两个 End 元素:
<EntityContainer Name="ExampleModelStoreContainer">
<EntitySet Name="Customers"
EntityType="ExampleModel.Store.Customers"
Schema="dbo" />
<EntitySet Name="Orders"
EntityType="ExampleModel.Store.Orders"
Schema="dbo" />
<AssociationSet Name="FK_CustomerOrders"
Association="ExampleModel.Store.FK_CustomerOrders">
<End Role="Customers" EntitySet="Customers" />
<End Role="Orders" EntitySet="Orders" />
</AssociationSet>
</EntityContainer>