This documentation is archived and is not being maintained.

RelationshipManager Class

Used to track relationships between objects in the object context.


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

public class RelationshipManager

The RelationshipManager type exposes the following members.

Public methodStatic memberCreateCreates a new RelationshipManager object.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetAllRelatedEndsReturns an enumeration of all the related ends managed by the relationship manager.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetRelatedCollection<TTargetEntity>Gets an EntityCollection<TEntity> of related objects with the specified relationship name and target role name.
Public methodGetRelatedEndReturns either an EntityCollection<TEntity> or EntityReference<TEntity> of the correct type for the specified target role in a relationship.
Public methodGetRelatedReference<TTargetEntity>Gets the EntityReference<TEntity> for a related object by using the specified combination of relationship name and target role name.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeRelatedCollection<TTargetEntity>Initializes an existing EntityCollection<TEntity> that was created by using the default constructor.
Public methodInitializeRelatedReference<TTargetEntity>Initializes an existing EntityReference<TEntity> that was created by using the default constructor.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodOnDeserializedInfrastructure. Used internally to deserialize entity objects along with the RelationshipManager instances.
Public methodOnSerializingCalled by Object Services to prepare an EntityKey for binary serialization with a serialized relationship.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

RelationshipManager is used to track relationships between objects in an object context. There is one instance of the RelationshipManager class for each relationship tracked in the object context. Relationships are defined by associations in a conceptual model. For more information, see Association (EDM).

The example in this topic is based on the Adventure Works Sales Model. The example adds new SalesOrderHeader entities to the Contact entity. Then it gets all related ends from the Contact entity and displays the 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.

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

    // Get all related ends
    IEnumerable<IRelatedEnd> relEnds =

    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, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.