ReferentialConstraint 元素 (SSDL)

以存储架构定义语言 (SSDL) 表示的 ReferentialConstraint 元素表示基础数据库中的外键约束(也称为“引用完整性约束”)。 约束的主体端和依赖端分别由 PrincipalDependent 子元素指定。 通过 PropertyRef 元素引用参与主体端和依赖端的列。

ReferentialConstraint 元素是 Association 元素的可选子元素。 如果未使用 ReferentialConstraint 元素映射 Association 元素中指定的外键约束,则必须使用 AssociationSetMapping 元素执行此操作。

ReferentialConstraint 元素可以具有以下子元素:

适用的特性

可以将任何数量的批注特性(自定义 XML 特性)应用于 ReferentialConstraint 元素。 然而,自定义特性可能不属于为 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)

其他资源

CSDL、SSDL 和 MSL 规范
ADO.NET Entity Data Model Tools