Export (0) Print
Expand All

RelatedEnd.TargetRoleName Property

Gets the role name at the target end of the relationship.

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

public string TargetRoleName { get; }

Property Value

Type: System.String
A String that is the role name.

Implements

IRelatedEnd.TargetRoleName

The role name is specified by the Role attribute of the End element in the association that defines this relationship in the 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 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);
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4
Show:
© 2015 Microsoft