共用方式為


ReferentialConstraint 項目 (EntityContainer CSDL)

在 實體資料模型 (EDM) 中,概念結構定義語言 (CSDL) 內的 ReferentialConstraint 項目會指定關聯的 Principal RoleDependent Role。參考條件約束則會影響 ObjectContext 中相關物件的行為。如需詳細資訊,請參閱參考條件約束 (Entity Framework)

在下列關聯中,VendorAddress 型別與 Address 型別相依。Address 物件可以與多個 VendorAddress 物件相關,因為 VendorAddress 只會將 Address 連結到 VendorVendor 可以有一個以上的 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>

另請參閱

概念

AssociationSet 項目 (EntityContainer CSDL)