【问题标题】:C# - Insert or update if exists in CRMC# - 如果 CRM 中存在,则插入或更新
【发布时间】:2018-01-31 12:32:22
【问题描述】:

从 c# 在 CRM 中执行 upsert 操作的最佳方法是什么。

在插入新记录之前,我是否需要每次都获取记录以检查它是否存在,或者有更好的方法吗?以及性能影响?

如果有人有任何例子吗?

【问题讨论】:

    标签: c# dynamics-crm dynamics-crm-online dynamics-crm-2015


    【解决方案1】:

    轰..轰。 UpsertRequest

        //use alternate key for product
        Entity productToCreate = new Entity("sample_product", "sample_productcode", productCode);
    
        productToCreate["sample_name"] = productName;
        productToCreate["sample_category"] = productCategory;
        productToCreate["sample_make"] = productMake;
        UpsertRequest request = new UpsertRequest()
        {
            Target = productToCreate
        };
    
            // Execute UpsertRequest and obtain UpsertResponse. 
            UpsertResponse response = (UpsertResponse)_serviceProxy.Execute(request);
            if (response.RecordCreated)
                Console.WriteLine("New record {0} is created!", productName);
            else
                Console.WriteLine("Existing record {0} is updated!", productName);
    

    对于 Microsoft Dynamics CRM Online 组织,此功能仅在您的组织已更新到 Dynamics CRM Online 2015 Update 1 时可用。此功能不适用于 Dynamics CRM(本地)。

    如果您使用的是本地或旧版本,则必须在调用创建/更新之前调用 Retrieve 以验证记录是否存在。

    【讨论】:

    • 我认为您甚至可以为 Upserts 配置自定义键(因此您不必依赖 GUID)
    • 正确。备用密钥将用于识别它是否已经可用。
    猜你喜欢
    • 2020-07-05
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-16
    相关资源
    最近更新 更多