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)

'Declaration
<SerializableAttribute> _
Public Class RelationshipManager
'Usage
Dim instance As RelationshipManager

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 the Entity Data Model (EDM). 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 advWorksContext As New AdventureWorksEntities
    Dim contact As New Contact
    Dim newSalesOrder1 As New SalesOrderHeader
    contact.SalesOrderHeader.Add(newSalesOrder1)
    Dim newSalesOrder2 As New SalesOrderHeader
    contact.SalesOrderHeader.Add(newSalesOrder2)

    Dim relEnds As IEnumerable(Of IRelatedEnd) = _
        CType(contact, IEntityWithRelationships) _
        .RelationshipManager.GetAllRelatedEnds

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

System.Object
  System.Data.Objects.DataClasses.RelationshipManager

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1
Show: