RelatedEnd.TargetRoleName 属性

定义

获取关系目标端处的角色名称。

public:
 property System::String ^ TargetRoleName { System::String ^ get(); };
public string TargetRoleName { get; }
member this.TargetRoleName : string
Public ReadOnly Property TargetRoleName As String

属性值

表示角色名称的 String

实现

示例

本示例向 实体添加新 SalesOrderHeader 实体 Contact 。 然后,它从 Contact 实体获取所有相关端,并显示每个相关端的关系名称、源角色名称和目标角色名称。

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

注解

角色名称由 Role 关联中定义概念模型中此关系的元素的 属性 End 指定。 有关详细信息,请参阅关联元素 (CSDL)

适用于

另请参阅