Edit

Share via


RelationshipManager.GetAllRelatedEnds Method

Definition

Returns an enumeration of all the related ends managed by the relationship manager.

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)

Returns

An IEnumerable<T> of objects that implement IRelatedEnd. An empty enumeration is returned when the relationships have not yet been populated.

Examples

This example adds new SalesOrderHeader entities to the Contact entity. Then it gets all related ends from the Contact entity and displays relationship name, source role name, and target role name for each related end,

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);
    }
}

Remarks

The GetAllRelatedEnds method returns an enumeration of EntityCollection<TEntity> and EntityReference<TEntity> objects. EntityCollection<TEntity> and EntityReference<TEntity> are concrete types that derive from RelatedEnd. The RelatedEnd abstract class implements the IRelatedEnd interface.

Applies to