RelatedEnd.SourceRoleName 属性

定义

获取关系的源端的角色名称。

public:
 property System::String ^ SourceRoleName { System::String ^ get(); };
public string SourceRoleName { get; }
member this.SourceRoleName : string
Public ReadOnly Property SourceRoleName 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)

适用于

另请参阅