C# - 如果 CRM 中存在则插入或更新
C# - Insert or update if exists in CRM
在 CRM 中从 C# 执行更新插入操作的最佳方法是什么。
我是否需要每次都获取记录以在插入新记录之前检查它是否存在,或者有更好的方法吗?以及性能效果?
有没有人有这方面的例子?
轰..轰。 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);
For Microsoft Dynamics CRM Online organizations, this feature is available only if your organization has updated to Dynamics CRM Online 2015 Update 1. This feature is not available for Dynamics CRM (on-premises).
如果您使用的是内部部署或旧版本,则必须在 Create/Update 调用之前调用 Retrieve 以验证记录是否存在。
在 CRM 中从 C# 执行更新插入操作的最佳方法是什么。
我是否需要每次都获取记录以在插入新记录之前检查它是否存在,或者有更好的方法吗?以及性能效果?
有没有人有这方面的例子?
轰..轰。 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);
For Microsoft Dynamics CRM Online organizations, this feature is available only if your organization has updated to Dynamics CRM Online 2015 Update 1. This feature is not available for Dynamics CRM (on-premises).
如果您使用的是内部部署或旧版本,则必须在 Create/Update 调用之前调用 Retrieve 以验证记录是否存在。