RelationshipManager RelationshipManager RelationshipManager RelationshipManager Class

Definition

Used to track relationships between objects in the object context.

public ref class RelationshipManager
[System.Serializable]
public class RelationshipManager
type RelationshipManager = class
Public Class RelationshipManager
Inheritance
RelationshipManagerRelationshipManagerRelationshipManagerRelationshipManager
Attributes

Examples

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.
    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

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).

Methods

Create(IEntityWithRelationships) Create(IEntityWithRelationships) Create(IEntityWithRelationships) Create(IEntityWithRelationships)

Creates a new RelationshipManager object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetAllRelatedEnds() GetAllRelatedEnds() GetAllRelatedEnds() GetAllRelatedEnds()

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

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetRelatedCollection<TTargetEntity>(String, String) GetRelatedCollection<TTargetEntity>(String, String) GetRelatedCollection<TTargetEntity>(String, String) GetRelatedCollection<TTargetEntity>(String, String)

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

GetRelatedEnd(String, String) GetRelatedEnd(String, String) GetRelatedEnd(String, String) GetRelatedEnd(String, String)

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

GetRelatedReference<TTargetEntity>(String, String) GetRelatedReference<TTargetEntity>(String, String) GetRelatedReference<TTargetEntity>(String, String) GetRelatedReference<TTargetEntity>(String, String)

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

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeRelatedCollection<TTargetEntity>(String, String, EntityCollection<TTargetEntity>) InitializeRelatedCollection<TTargetEntity>(String, String, EntityCollection<TTargetEntity>) InitializeRelatedCollection<TTargetEntity>(String, String, EntityCollection<TTargetEntity>) InitializeRelatedCollection<TTargetEntity>(String, String, EntityCollection<TTargetEntity>)

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

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

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

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialized(StreamingContext) OnDeserialized(StreamingContext) OnDeserialized(StreamingContext) OnDeserialized(StreamingContext)

Used internally to deserialize entity objects along with the RelationshipManager instances.

OnSerializing(StreamingContext) OnSerializing(StreamingContext) OnSerializing(StreamingContext) OnSerializing(StreamingContext)

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

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to