共用方式為


End 項目 (SSDL)

存放結構定義語言 (SSDL) 中的 End 項目會指定基礎資料庫中外部索引鍵條件約束之某一端點上資料表和資料列數。 End 項目可以是 Association 項目AssociationSet 項目的子項目。 在這兩種情況下,可能的子項目和適用的屬性都不相同。

End 項目為 Association 項目的子項目

End 項目 (做為 Association 項目的子項目) 會指定外部索引鍵條件約束 (分別使用 TypeMultiplicity 屬性) 之端點上的資料表和資料列數。 外部索引鍵條件約束的端點是定義為 SSDL 關聯的一部分;SSDL 關聯必須擁有兩個端點。

End 項目可以擁有下列子項目 (依列出的順序):

適用屬性

下表描述的屬性可套用於 End 項目 (當它是 Association 項目的子項目時)。

屬性名稱 必要

Type

位於外部索引鍵條件約束端點上之 SSDL 實體集的完整名稱。

Role

在對應之 ReferentialConstraint 項目 (如果使用的話) 的 PrincipalDependent 項目中的 Role 屬性的值。

Multiplicity

10..1* 取決於可以在外部索引鍵條件約束之端點上的資料列數。

  • 1 表示外部索引鍵條件約束端點上只存在一個資料列。

  • 0..1 表示外部索引鍵條件約束端點上存在零個或一個資料列。

  • * 表示外部索引鍵條件約束端點上存在零個、一個或多個資料列。

Bb896336.note(zh-tw,VS.100).gif注意:
可以將任何數量的 Annotation 屬性 (自訂 XML 屬性) 套用至 End 項目。不過,自訂屬性不可屬於任何 XML 命名空間,這是保留供 CSDL 使用。任兩個自訂屬性的完整名稱不能相同。

範例

下列範例顯示的 Association 項目定義 FK_CustomerOrders 外部索引鍵條件約束。 每個 End 項目上所指定的 Multiplicity 值表示 Orders 資料表中的很多資料列可以與 Customers 資料表中的一個資料列產生關聯,但是 Customers 資料表中只有一個資料列可以與 Orders 資料表中的某個資料列產生關聯。 此外,如果 Customers 資料表中的資料列已刪除,OnDelete 項目表示將要刪除 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 項目可以擁有下列子項目 (依列出的順序):

適用屬性

下表描述的屬性可套用於 End 項目 (當它是 AssociationSet 項目的子項目時)。

屬性名稱 必要

EntitySet

位於外部索引鍵條件約束端點上之 SSDL 實體集的名稱。

Role

在對應之 Association 項目的某個 End 項目上所指定的其中一個 Role 屬性的值。

Bb896336.note(zh-tw,VS.100).gif注意:
可以將任何數量的 Annotation 屬性 (自訂 XML 屬性) 套用至 End 項目。不過,自訂屬性不可屬於任何 XML 命名空間,這是保留供 CSDL 使用。任兩個自訂屬性的完整名稱不能相同。

範例

下列範例顯示的 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>

另請參閱

概念

Entity Framework 概觀
SSDL 規格

其他資源

CSDL、SSDL 和 MSL 規格
ADO.NET Entity Data Model Tools