UpsertMultiple の使用 (プレビュー)

[このトピックはプレリリース ドキュメントであり、変更されることがあります。]

重要

これはプレビュー機能です。

プレビュー機能は運用環境での使用を想定しておらず、機能が制限されている可能性があります。 これらの機能を公式リリースの前に使用できるようにすることで、顧客が一足先にアクセスし、そこからフィードバックを得ることができます。

このテーブルが Dataverse に存在するかどうかが不明な場合は、Upsert を使用してデータを外部ソースと統合します。 多くの場合、Upsert 操作はレコードを識別する際に、代替キーに依存します。 UpsertMultiple を使用して Upsert 操作を一括で実行します。

UpsertMultipleRequest クラスを使用します。

この静的 UpsertMultipleExample メソッドは、代替キーとして構成された samples_accountname という名前の文字列の列を持つ、samples_bankaccount テーブルに依存します。 これには、samples_description という名前の文字列の列もあります。 このコードは代替キー値の指定に keyName と keyValue を設定するエンティティ コンストラクター を使用します。

/// <summary>
/// Demonstrates using UpsertMultiple with alternate key values
/// </summary>
/// <param name="service">The authenticated IOrganizationService instance</param>
static void UpsertMultipleExample(IOrganizationService service)
{
    var tableLogicalName = "samples_bankaccount";
    // samples_accountname string column is configued as an alternate key
    // for the samples_bankaccount table
    var altKeyColumnLogicalName = "samples_accountname";

    // Create one record to update with upsert
    service.Create(new Entity(tableLogicalName)
    {
        Attributes =
        {
            {altKeyColumnLogicalName, "Record For Update"},
            {"samples_description","A record to update using Upsert" }
        }
    });

    // Using the Entity constructor to specify alternate key
    Entity toUpdate = new(
            entityName: tableLogicalName,
            keyName: altKeyColumnLogicalName,
            // Same alternate key value as created record.
            keyValue: "Record For Update");
    toUpdate["samples_description"] = "Updated using Upsert";

    Entity toCreate = new(
        entityName: tableLogicalName,
        keyName: altKeyColumnLogicalName,
        keyValue: "Record For Create");
    toCreate["samples_description"] = "A record to create using Upsert";

    // Add the records to a collection
    EntityCollection records = new()
    {
        EntityName = tableLogicalName,
        Entities = { toUpdate, toCreate }
    };

    // Send the request
    UpsertMultipleRequest request = new()
    {
        Targets = records
    };

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

    // Process the responses:
    foreach (UpsertResponse item in response.Results)
    {
        Console.WriteLine($"Record {(item.RecordCreated ? "Created" : "Updated")}");
    }
}

出力:

Record Updated
Record Created

空き時間

UpsertMultipleCreateMultipleUpdateMultiple に対応したテーブルで使用できます。 これには、すべてのエラスティック テーブルが含まれます。 標準テーブルでの可用性 で見つかったクエリは UpsertMultiple の結果を返しません。

使用例

GitHub github.com/microsoft/PowerApps-Samples にサンプル コードが用意されています。

サンプル: .NET 用 SDK 一括操作の使用UpsertMultiple プロジェクト を見つけます

参照

一括操作メッセージを使う
エラスティック テーブル
サンプル: .NET 用 SDK 一括操作の使用