共用方式為


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 所指定。 如需詳細資訊,請參閱 Association 項目 (CSDL)

適用於

另請參閱