Κοινή χρήση μέσω


RetrieveMultipleRequest Class

Definition

Contains the data that is needed to retrieve a collection of records that satisfy the specified query criteria.

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

/// <summary>
/// Demonstrates using the RetrieveMultipleRequest
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
/// <param name="queryType">Number indicating which type of QueryBase to use</param>
/// <exception cref="IndexOutOfRangeException"></exception>
static void RetrieveMultipleRequestExample(IOrganizationService service, int queryType)
{
    QueryBase query;

    // Set the query based on the queryType parameter
    switch (queryType)
    {
        // QueryExpression
        case 1:
            query = new QueryExpression("account")
            {
                TopCount = 5,
                ColumnSet = new ColumnSet("name", "primarycontactid", "address1_city"),
                Criteria = new FilterExpression(LogicalOperator.And)
                {
                    Conditions =
                    {
                        new ConditionExpression
                        {
                            AttributeName = "address1_city",
                            Operator = ConditionOperator.Equal,
                            Values = {"Redmond"}
                        }
                    }
                },
                Orders =
                {
                    {
                        new OrderExpression("name",OrderType.Ascending) 
                    }
                }                        
            };
            break;
        // FetchExpression
        case 2:
            string fetchXml = @"<fetch top='5'>
<entity name='account'>
<attribute name='name' />
<attribute name='primarycontactid' />
<attribute name='primarycontactid' />
<filter type='and'>
<condition attribute='address1_city' 
                     operator='eq' 
                     value='Redmond' />
</filter>
<order attribute='name' />
</entity>
</fetch>";

            query = new FetchExpression(fetchXml);
            break;
        // QueryByAttribute
        case 3:
            query = new QueryByAttribute("account") {
                PageInfo = new PagingInfo() { Count = 5, PageNumber = 1 },
                ColumnSet = new ColumnSet("name", "primarycontactid", "address1_city"),                        
                Orders = { { new OrderExpression("name", OrderType.Ascending) } }                         
            };
            // QueryByAttribute is for simple queries.
            // It doesn't allow for operators other than 'equals'
            // or complex queries.
            ((QueryByAttribute)query).AddAttributeValue("address1_city", "Redmond");
            break;
        default:
            string message = $"exampleNumber {queryType} isn't valid. Use 1, 2, or 3";
            throw new IndexOutOfRangeException(message);
    }

    RetrieveMultipleRequest request = new()
    {
        Query = query
    };

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

    // Show the data
    foreach (Entity record in response.EntityCollection.Entities)
    {
        string primarycontactName = record.Contains("primarycontactid") ? 
            record.FormattedValues["primarycontactid"] : 
            string.Empty;

        Console.WriteLine($"ID:{record.Id}");
        Console.WriteLine($"\tname:{record.GetAttributeValue<string>("name")}");
        Console.WriteLine($"\tprimary contact name:{primarycontactName}");
        Console.WriteLine($"\tcity:{record.GetAttributeValue<string>("address1_city")}");
        Console.WriteLine();
    }
}

Output:

ID:86914942-34cb-ed11-b596-0022481d68cd
  name:A. Datum Corporation (sample)
  primary contact name:Rene Valdes (sample)
  city:Redmond

ID:80914942-34cb-ed11-b596-0022481d68cd
  name:City Power & Light (sample)
  primary contact name:Scott Konersmann (sample)
  city:Redmond

ID:82914942-34cb-ed11-b596-0022481d68cd
  name:Contoso Pharmaceuticals (sample)
  primary contact name:Robert Lyon (sample)
  city:Redmond        

Remarks

Usage

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

Privileges and Access Rights

To perform this action, the caller must have read privileges on the specified entities in the Query property and read access rights on the records that are returned from the query.

Notes for Callers

This message supports queries that use the QueryExpression, FetchExpression, or QueryByAttribute classes.

For more information, see Query data using the SDK for .NET

It is generally preferred to use the RetrieveMultiple(QueryBase) method. You must use the RetrieveMultipleRequest class if you use optional parameters, but optional parameters have few use cases when retrieving data.

The collection of returned records from this message contains only the records for which the caller has read access. The returned records contain values for specified properties in the query that are valid for retrieval and for which the calling user has access rights. Any other property values are not returned. For more information about column security, see Column-level security to control access.

Supported Tables

See Message support for tables for an example query you can use to get the list of tables you can use with the RetrieveMultiple message.

Constructors

RetrieveMultipleRequest()

Initializes a new instance of the RetrieveMultipleRequest 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)
Parameters

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

(Inherited from OrganizationRequest)
Query

Gets or sets the query criteria for the retrieval. Required.

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)

Applies to

See also