Jaa


RetrieveEntityKeyRequest Class

Definition

Contains data that is needed to retrieve an alternate key.

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

The following RetrieveEntityKeyById and RetrieveEntityKeyByName static methods both use the following OutputEntityKeyInformation to show details of the table alternate key.

/// <summary>
/// Retrieves a table alternate key by ID
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void RetrieveEntityKeyById(IOrganizationService service) {

    Guid keyID = new("4d9ca2c2-d875-ee11-8179-000d3a993550");

    RetrieveEntityKeyRequest request = new() { 
          MetadataId = keyID
    };

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

    OutputEntityKeyInformation(response.EntityKeyMetadata);

}
/// <summary>
/// Retrieves a table alternate key by name
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void RetrieveEntityKeyByName(IOrganizationService service)
{
    string logicalName = "sample_uniquename";
    string tableLogicalName = "sample_bankaccount";

    RetrieveEntityKeyRequest request = new()
    {
          LogicalName = logicalName,
          EntityLogicalName = tableLogicalName
    };

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

    OutputEntityKeyInformation(response.EntityKeyMetadata);
}

//Outputs details about retrieved table alternate key.
static void OutputEntityKeyInformation(EntityKeyMetadata entityKeyMetadata)
{
    Console.WriteLine($"SchemaName:{entityKeyMetadata.SchemaName}");
    Console.WriteLine($"DisplayName:{entityKeyMetadata.DisplayName.UserLocalizedLabel.Label}");
    Console.WriteLine($"EntityLogicalName:{entityKeyMetadata.EntityLogicalName}");
    Console.WriteLine($"LogicalName:{entityKeyMetadata.LogicalName}");
    Console.WriteLine("KeyAttributes:");
    foreach (var columnName in entityKeyMetadata.KeyAttributes) {
        Console.WriteLine($"\t{columnName}");
    }
}

Output:

SchemaName:sample_UniqueName
DisplayName:Unique Name
EntityLogicalName:sample_bankaccount
LogicalName:sample_uniquename
KeyAttributes:
        sample_accountname

Remarks

This message takes the table name and key name as input values to retrieve the specified key for the table.

Usage

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

Notes for Callers

You have to specify the EntityLogicalName and the LogicalName to specify the key you want to retrieve.

Constructors

RetrieveEntityKeyRequest()

Initializes a new instance of the RetrieveEntityKeyRequest class.

Properties

EntityLogicalName

Gets or sets the logical name of the table.

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)
LogicalName

Gets or sets the logical name of the key.

MetadataId

Gets or sets the metadata ID.

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