Freigeben über


CreateMultipleRequest Class

Definition

Contains the data to create multiple records of the same type with a single web request.

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

Examples

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

/// <summary>
/// Demonstrates the use of the CreateMultiple Message
/// </summary>
/// <param name="service">The authenticated IOrganizationService instance.</param>
/// <param name="recordsToCreate">A list of records of the same table to create.</param>
/// <returns>The Guid values of the records created.</returns>
static Guid[] CreateMultipleExample(IOrganizationService service,
    List<Entity> recordsToCreate)
{

    // Create an EntityCollection populated with the list of entities.
    EntityCollection entities = new(recordsToCreate)
    {
        // All the records must be for the same table.
        EntityName = recordsToCreate[0].LogicalName
    };

    // Instantiate CreateMultipleRequest
    CreateMultipleRequest createMultipleRequest = new()
    {
        Targets = entities,
    };

    // Send the request
    CreateMultipleResponse createMultipleResponse =
                (CreateMultipleResponse)service.Execute(createMultipleRequest);

    // Return the Ids of the records created.
    return createMultipleResponse.Ids;
}

Sample code on GitHub

Create and Update Multiple Sample

Remarks

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

CreateMultiple will work for all elastic tables, but only for those standard tables that have enabled this message. You can use the following static IsMessageAvailable method to determine whether a standard table supports the CreateMultiple message. Set the table logical name as the entityLogicalName parameter and CreateMultiple as the messageName parameter.

/// <summary>
/// Detect whether a specified message is supported for the specified table.
/// </summary>
/// <param name="service">The IOrganizationService instance.</param>
/// <param name="entityLogicalName">The logical name of the table.</param>
/// <param name="messageName">The name of the message.</param>
/// <returns>Whether the table supports the message.</returns>
public static bool IsMessageAvailable(
    IOrganizationService service,
    string entityLogicalName,
    string messageName)
{
    QueryExpression query = new("sdkmessagefilter")
    {
        ColumnSet = new ColumnSet("sdkmessagefilterid"),
        Criteria = new FilterExpression(LogicalOperator.And)
        {
            Conditions = {
            new ConditionExpression(
                attributeName:"primaryobjecttypecode",
                conditionOperator: ConditionOperator.Equal,
                value: entityLogicalName)
            }
        },
        LinkEntities = {
            new LinkEntity(
                linkFromEntityName:"sdkmessagefilter",
                linkToEntityName:"sdkmessage",
                linkFromAttributeName:"sdkmessageid",
                linkToAttributeName:"sdkmessageid",
                joinOperator: JoinOperator.Inner)
            {
                LinkCriteria = new FilterExpression(LogicalOperator.And){
                Conditions = {
                    new ConditionExpression(
                        attributeName:"name",
                        conditionOperator: ConditionOperator.Equal,
                        value: messageName)
                    }
                }
            }
        }
    };

    EntityCollection entityCollection = service.RetrieveMultiple(query);

    return entityCollection.Entities.Count.Equals(1);
}

For more information see: Bulk Operation messages and Sample: Use CreateMultiple and UpdateMultiple.

Constructors

CreateMultipleRequest()

Initializes a new instance of the CreateMultipleRequest 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)
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)
Targets

Gets or sets the collection of entities representing records to create.

Applies to

See also