Breyta

Deila með


RelationshipManager Class

Definition

Used to track relationships between objects in the object context.

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

Examples

This 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);
    }
}

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)

Creates a new RelationshipManager object.

Equals(Object)

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

(Inherited from Object)
GetAllRelatedEnds()

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

GetHashCode()

Serves as the default hash function.

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

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

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)

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

GetType()

Gets the Type of the current instance.

(Inherited from Object)
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>)

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

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialized(StreamingContext)

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

OnSerializing(StreamingContext)

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

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to