ReferentialConstraint Element (Association CSDL)

In the Entity Data Model (EDM), the ReferentialConstraint element in conceptual schema definition language (CSDL) specifies the Principal Role and the Dependent Role of an association. Referential constraints affect the behavior of related objects in an ObjectContext. For more information, see Referential Constraints (Entity Framework).

In the following association the VendorAddress type is dependent on the Address type. An Address object can be related to multiple VendorAddress objects because VendorAddress simply links an Address with a Vendor. A Vendor can have more than one Address.

  <Association Name="FK_VendorAddress_Address_AddressID">
    <End Role="Address" Type="Adventureworks.Address" Multiplicity="1" />
    <End Role="VendorAddress" Type="Adventureworks.VendorAddress" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="Address">
        <PropertyRef Name="AddressID" />
      </Principal>
      <Dependent Role="VendorAddress">
        <PropertyRef Name="AddressID" />
      </Dependent>
    </ReferentialConstraint>
  </Association>

<EntityType Name="VendorAddress">
    <Key>
      <PropertyRef Name="VendorID" />
      <PropertyRef Name="AddressID" />
    </Key>
    <Property Name="VendorID" Type="Int32" Nullable="false" />
    <Property Name="AddressID" Type="Int32" Nullable="false" />
    <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
    <NavigationProperty Name="Address"
     Relationship="Adventureworks.FK_VendorAddress_Address_AddressID"
       FromRole="VendorAddress" ToRole="Address" />
    <NavigationProperty Name="AddressType"
Relationship="Adventureworks.FK_VendorAddress_AddressType_AddressTypeID
   " FromRole="VendorAddress" ToRole="AddressType" />
    <NavigationProperty Name="Vendor"
     Relationship="Adventureworks.FK_VendorAddress_Vendor_VendorID"
     FromRole="VendorAddress" ToRole="Vendor" />
  </EntityType>

<EntityContainer Name="AdventureworksContext">

   <EntitySet Name="VendorAddress" 
          EntityType="Adventureworks.VendorAddress" />

  <AssociationSet Name="FK_VendorAddress_Address_AddressID"
     Association="Adventureworks.FK_VendorAddress_Address_AddressID">
      <End Role="Address" EntitySet="Address" />
      <End Role="VendorAddress" EntitySet="VendorAddress" />
  </AssociationSet>

</EntityContainer>

See Also

Concepts

AssociationSet Element (EntityContainer CSDL)