RelationshipManager Class

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


Creates a new RelationshipManager object.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


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


Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetRelatedCollection<TTargetEntity>(String, String)

Gets an EntityCollection<TEntity> of related objects with the specified relationship name and target role name.

System_CAPS_pubmethodGetRelatedEnd(String, String)

Returns either an EntityCollection<TEntity> or EntityReference<TEntity> of the correct type for the specified target role in a relationship.

System_CAPS_pubmethodGetRelatedReference<TTargetEntity>(String, String)

Gets the EntityReference<TEntity> for a related object by using the specified combination of relationship name and target role name.


Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeRelatedCollection<TTargetEntity>(String, String, EntityCollection<TTargetEntity>)

Initializes an existing EntityCollection<TEntity> that was created by using the default constructor.

System_CAPS_pubmethodInitializeRelatedReference<TTargetEntity>(String, String, EntityReference<TTargetEntity>)

Initializes an existing EntityReference<TEntity> that was created by using the default constructor.


Creates a shallow copy of the current Object.(Inherited from Object.)


This API supports the product infrastructure and is not intended to be used directly from your code. Used internally to deserialize entity objects along with the RelationshipManager instances.


Called by Object Services to prepare an EntityKey for binary serialization with a serialized relationship.


Returns 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 Element (CSDL).

The example in this topic is based on the AdventureWorks 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
Available since 3.5

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

Return to top
© 2015 Microsoft