RelatedEnd.SourceRoleName Eigenschaft

Definition

Ruft den Rollennamen am Quellenende der Beziehung ab.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

Eigenschaftswert

Ein String, der den Rollennamen enthält.A String that is the role name.

Implementiert

Beispiele

Das Beispiel in diesem Thema basiert auf dem Microsoft SQL Server Product Samples: Database, das vom Entity Data Model-Assistentengeneriert wurde.The example in this topic is based on the Microsoft SQL Server Product Samples: Database, which was generated by the Entity Data Model Wizard.

Im folgenden Beispiel werden der Contact Entität neue SalesOrderHeader Entitäten hinzugefügt.The following example adds new SalesOrderHeader entities to the Contact entity. Anschließend werden alle verknüpften Enden von der Contact Entität abgerufen und Beziehungs Name, Quell Rollenname und Ziel Rollenname für jedes verknüpfte Ende angezeigt.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

Hinweise

Der Rollenname wird durch das Role-Attribut des End-Elements in der Zuordnung angegeben, die diese Beziehung im konzeptionellen Modell definiert.The role name is specified by the Role attribute of the End element in the association that defines this relationship in the conceptual model. Weitere Informationen finden Sie unter Zuordnungselement (CSDL).For more information, see Association Element (CSDL).

Gilt für:

Siehe auch