共用方式為


RelationshipManager.GetAllRelatedEnds 方法

定義

傳回關聯性管理員所管理之所有相關端的列舉型別 (Enumeration)。

public:
 System::Collections::Generic::IEnumerable<System::Data::Objects::DataClasses::IRelatedEnd ^> ^ GetAllRelatedEnds();
public System.Collections.Generic.IEnumerable<System.Data.Objects.DataClasses.IRelatedEnd> GetAllRelatedEnds ();
member this.GetAllRelatedEnds : unit -> seq<System.Data.Objects.DataClasses.IRelatedEnd>
Public Function GetAllRelatedEnds () As IEnumerable(Of IRelatedEnd)
Public Iterator Function GetAllRelatedEnds () As IEnumerable(Of IRelatedEnd)

傳回

實作 IEnumerable<T> 之物件的 IRelatedEnd。 當這些關聯性尚未填入 (Populate) 時,就會傳回空的列舉型別。

範例

本範例會將新的 SalesOrderHeader 實體新增至 Contact 實體。 然後它會從 Contact 實體取得所有相關的結尾,並顯示每個相關端的關聯性名稱、來源角色名稱和目標角色名稱。

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    Contact contact = new Contact();

    // Create a new SalesOrderHeader.
    SalesOrderHeader newSalesOrder1 = new SalesOrderHeader();
    // Add SalesOrderHeader to the Contact.
    contact.SalesOrderHeaders.Add(newSalesOrder1);

    // Create another SalesOrderHeader.
    SalesOrderHeader newSalesOrder2 = new SalesOrderHeader();
    // Add SalesOrderHeader to the Contact.
    contact.SalesOrderHeaders.Add(newSalesOrder2);

    // Get all related ends
    IEnumerable<IRelatedEnd> relEnds =
        ((IEntityWithRelationships)contact).RelationshipManager
        .GetAllRelatedEnds();

    foreach (IRelatedEnd relEnd in relEnds)
    {
        Console.WriteLine("Relationship Name: {0}", relEnd.RelationshipName);
        Console.WriteLine("Source Role Name: {0}", relEnd.SourceRoleName);
        Console.WriteLine("Target Role Name: {0}", relEnd.TargetRoleName);
    }
}

備註

方法GetAllRelatedEnds會傳回和 EntityReference<TEntity> 物件的列舉EntityCollection<TEntity>EntityCollection<TEntity>EntityReference<TEntity> 是衍生自 RelatedEnd的具象型別。 抽象類會 RelatedEnd 實作 IRelatedEnd 介面。

適用於