RelationshipManager.GetAllRelatedEnds 方法

定义

返回关系管理器管理的所有相关端的枚举。

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。 如果尚未填充关系,则返回空枚举。

示例

本示例向 实体添加新 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 接口。

适用于