Export (0) Print
Expand All

IRelatedEnd Interface

Defines the end of a relationship.

Namespace:  System.Data.Objects.DataClasses
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public interface IRelatedEnd

The IRelatedEnd type exposes the following members.

  NameDescription
Public propertyIsLoadedGets a value that indicates whether all related objects have been loaded.
Public propertyRelationshipNameGets the name of the relationship in which this related end participates.
Public propertyRelationshipSetReturns a reference to the metadata for the related end.
Public propertySourceRoleNameGets the role name at the source end of the relationship.
Public propertyTargetRoleNameGets the role name at the target end of the relationship.
Top

  NameDescription
Public methodAdd(IEntityWithRelationships)Adds an object to the related end.
Public methodAdd(Object)Adds an object to the related end.
Public methodAttach(IEntityWithRelationships)Defines a relationship between two attached objects.
Public methodAttach(Object)Defines a relationship between two attached objects.
Public methodCreateSourceQueryReturns an IEnumerable that represents the objects that belong to the related end.
Public methodGetEnumeratorReturns an IEnumerator that iterates through the collection of related objects.
Public methodLoad()Loads the related object or objects into this related end with the default merge option.
Public methodLoad(MergeOption)Loads the related object or objects into the related end with the specified merge option.
Public methodRemove(IEntityWithRelationships)Removes an object from the collection of objects at the related end.
Public methodRemove(Object)Removes an object from the collection of objects at the related end.
Top

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.

The example in this topic is based on the Adventure Works 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);
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft