RelatedEnd.SourceRoleName 屬性

定義

取得位於關聯性來源端的角色名稱。Gets the role name at the source end of the relationship.

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

屬性值

String

成為角色名稱的 StringA String that is the role name.

實作

範例

本主題中的範例是以實體資料模型 Wizard產生的Microsoft SQL Server 產品範例: Database為基礎。The example in this topic is based on the Microsoft SQL Server Product Samples: Database, which was generated by the Entity Data Model Wizard.

下列範例會將新 SalesOrderHeader 實體新增至 Contact 實體。The following example adds new SalesOrderHeader entities to the Contact entity. 然後,它會從實體取得所有相關端, Contact 並且顯示每個相關端的關聯性名稱、來源角色名稱和目標角色名稱。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);
    }
}
Using context As New AdventureWorksEntities()
    Dim contact As New Contact()

    ' Create a new SalesOrderHeader. 
    Dim newSalesOrder1 As New SalesOrderHeader()
    ' Add SalesOrderHeader to the Contact. 
    contact.SalesOrderHeaders.Add(newSalesOrder1)

    ' Create another SalesOrderHeader. 
    Dim newSalesOrder2 As New SalesOrderHeader()
    ' Add SalesOrderHeader to the Contact. 
    contact.SalesOrderHeaders.Add(newSalesOrder2)

    ' Get all related ends 
    Dim relEnds As IEnumerable(Of IRelatedEnd) = DirectCast(contact, IEntityWithRelationships).RelationshipManager.GetAllRelatedEnds()

    For Each relEnd As IRelatedEnd 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)
    Next
End Using

備註

角色名稱是由在 Role End 概念模型中定義此關聯性之關聯中的元素屬性所指定。The role name is specified by the Role attribute of the End element in the association that defines this relationship in the conceptual model. 如需詳細資訊,請參閱 Association 項目 (CSDL)For more information, see Association Element (CSDL).

適用於

另請參閱