RetrieveRelationshipRequest Class

Definition

Contains the data that is needed to retrieve table relationship metadata.

public ref class RetrieveRelationshipRequest sealed : Microsoft::Xrm::Sdk::OrganizationRequest
[System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/2011/Contracts")]
public sealed class RetrieveRelationshipRequest : Microsoft.Xrm.Sdk.OrganizationRequest
[<System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/2011/Contracts")>]
type RetrieveRelationshipRequest = class
    inherit OrganizationRequest
Public NotInheritable Class RetrieveRelationshipRequest
Inherits OrganizationRequest
Inheritance
RetrieveRelationshipRequest
Attributes

Examples

The following example shows how to use this message. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface instance.

This example uses the Account_Tasks one-to-many relationship by default, but you can use the roleprivileges_association to try a many-to-many relationship.

/// <summary>
/// Retrieves a table relationship definition by name
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void RetrieveRelationshipExample(IOrganizationService service) {

    // Example One-to-many
    string schemaName = "Account_Tasks";

    // Example many-to-many
    //string schemaName = "roleprivileges_association";

    RetrieveRelationshipRequest request = new() { 
          Name = schemaName,
          // MetadataId isn't used in this example
    };

    var response = (RetrieveRelationshipResponse)service.Execute(request);

    // Write the output for both types of relationships

    switch (response.RelationshipMetadata.RelationshipType)
    {
        case Microsoft.Xrm.Sdk.Metadata.RelationshipType.OneToManyRelationship:

            // Cast the RelationshipMetadata
            var one2N = (OneToManyRelationshipMetadata)response.RelationshipMetadata;

            Console.WriteLine($"One: {one2N.ReferencedEntity}" +
                $".{one2N.ReferencedAttribute}");
            Console.WriteLine($"Many: {one2N.ReferencingEntity}" +
                $".{one2N.ReferencingAttribute}");

            break;

        case Microsoft.Xrm.Sdk.Metadata.RelationshipType.ManyToManyRelationship:

            // Cast the RelationshipMetadata
            var n2N = (ManyToManyRelationshipMetadata)response.RelationshipMetadata;

            Console.WriteLine($"Between {n2N.Entity1LogicalName} " +
                $"and {n2N.Entity2LogicalName} ");
            Console.WriteLine($"Intersect Table: {n2N.IntersectEntityName} ");

            break;

        default:
            // This should not occur.
            break;
    }
}

Output:

Using Account_Tasks:

One: account.accountid
Many: task.regardingobjectid

Using roleprivileges_association:

Between privilege and role
Intersect Table: roleprivileges

Sample code on GitHub

Create and retrieve table relationships

Remarks

Usage

Pass an instance of this class to the Execute(OrganizationRequest) method, which returns an instance of RetrieveRelationshipResponse.

Privileges and Access Rights

Table relationship definitions are available for all users.

Notes for Callers

You can use either the SchemaName or the MetadataId of the relationship.

Constructors

RetrieveRelationshipRequest()

Initializes a new instance of the RetrieveRelationshipRequest class.

Properties

ExtensionData

Gets or sets the structure that contains extra data. Optional.

(Inherited from OrganizationRequest)
Item[String]

Gets or sets the indexer for the Parameters collection.

(Inherited from OrganizationRequest)
MetadataId

Gets or sets the MetadataId of the RelationshipMetadataBase to be retrieved. Optional.

Name

Gets or sets the schema name for the entity relationship to be retrieved. Optional.

Parameters

Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
RequestId

Gets or sets the ID of the request. Optional.

(Inherited from OrganizationRequest)
RequestName

Gets or sets the name of the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
RetrieveAsIfPublished

Gets or sets whether to retrieve the metadata that has not been published. Required.

Applies to