IRelatedEnd Interface

Definition

Defines the end of a relationship.

public interface class IRelatedEnd
public interface IRelatedEnd
type IRelatedEnd = interface
Public Interface IRelatedEnd
Derived

Examples

The example in this topic is based on the AdventureWorks Sales Model, which was generated by the Entity Data Model Wizard.

The following 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);
    }
}
Using context As New AdventureWorksEntities()
    Dim contact As New Contact()

    ' Create a new SalesOrderHeader. 
    Dim newSalesOrder1 As New SalesOrderHeader()
    ' Add SalesOrderHeader to the Contact. 
    contact.SalesOrderHeaders.Add(newSalesOrder1)

    ' Create another SalesOrderHeader. 
    Dim newSalesOrder2 As New SalesOrderHeader()
    ' Add SalesOrderHeader to the Contact. 
    contact.SalesOrderHeaders.Add(newSalesOrder2)

    ' Get all related ends 
    Dim relEnds As IEnumerable(Of IRelatedEnd) = DirectCast(contact, IEntityWithRelationships).RelationshipManager.GetAllRelatedEnds()

    For Each relEnd As IRelatedEnd 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)
    Next
End Using

Remarks

IRelatedEnd defines the requirements for an object that represents an end in an association. This interface is implemented by the RelatedEnd class. RelatedEnd is the base class for the EntityCollection<TEntity> and EntityReference<TEntity> classes.

Properties

IsLoaded

Gets a value that indicates whether all related objects have been loaded.

RelationshipName

Gets the name of the relationship in which this related end participates.

RelationshipSet

Returns a reference to the metadata for the related end.

SourceRoleName

Gets the role name at the source end of the relationship.

TargetRoleName

Gets the role name at the target end of the relationship.

Methods

Add(IEntityWithRelationships)

Adds an object to the related end.

Add(Object)

Adds an object to the related end.

Attach(IEntityWithRelationships)

Defines a relationship between two attached objects.

Attach(Object)

Defines a relationship between two attached objects.

CreateSourceQuery()

Returns an IEnumerable that represents the objects that belong to the related end.

GetEnumerator()

Returns an IEnumerator that iterates through the collection of related objects.

Load()

Loads the related object or objects into this related end with the default merge option.

Load(MergeOption)

Loads the related object or objects into the related end with the specified merge option.

Remove(IEntityWithRelationships)

Removes an object from the collection of objects at the related end.

Remove(Object)

Removes an object from the collection of objects at the related end.

Applies to