Dynamics CRM SDK:批量更新实体中的特定字段 [英] Dynamics CRM SDK : Batch update specific fields in entity
问题描述
我是Dynamics CRM开发的新手。我想使用Dynamics CRM Online中的批量更新方法批量更新实体中的某些字段。
我正在使用以下代码执行批量更新:
I am new to Dynamics CRM development. I want to batch update certain fields in Entity using Batch update method in Dynamics CRM Online. I am using below code for performing batch update:
var multipleRequest = new ExecuteMultipleRequest()
{
Settings = new ExecuteMultipleSettings()
{
ContinueOnError = false,
ReturnResponses = true
},
Requests = new OrganizationRequestCollection()
};
foreach (var entity in entities.Entities)
{
UpdateRequest updateRequest = new UpdateRequest { Target = entity };
multipleRequest.Requests.Add(updateRequest);
}
ExecuteMultipleResponse multipleResponse = (ExecuteMultipleResponse)service.Execute(multipleRequest);
如何仅指定要更新的字段而不是整个实体进行更新?
How can I specify only fields which I want to update instead of entire entity being updated?
注意:我有大约200,000条记录要使用上面的代码进行更新。当前,更新单批1000条记录大约需要1.5分钟。因此,我们正在考虑一种仅更新必需字段的方法。
Note: I have around 200,000 records to update using the above code. Currently it takes around 1.5 minute to update a single batch of 1000 records. So was thinking a way to update only required fields.
推荐答案
您必须查看EntityCollection <$ c $的方式c>实体已满。如果使用RetrieveMultiple进行检索,则Pull the minimum字段可能是本地Name字段& PK ID字段将默认出现。
You have to look at the way how the EntityCollection entities
is filled up. If retrieving using RetrieveMultiple, then Pull the minimal fields may be the native Name field & PK Id field will come by default. This way not the whole entity will be updated back.
避免使用 AllColumns = true
。使用ColumnSet获得验证所需的最少字段。
Avoid using AllColumns = true
. Use ColumnSet to get minimal fields needed for validation.
ColumnSet = new ColumnSet("field_needed"),
下一步,仅分配以下内部循环之类的必要字段。
Next, assign only the necessary fields like below inside loop.
foreach (var entity in entities.Entities)
{
UpdateRequest updateRequest = new UpdateRequest { Target = entity };
entity.Attributes["field_to_update"] = "field_value";
multipleRequest.Requests.Add(updateRequest);
}
我的答案将帮助您了解问题出在哪里&纠正它。如Nicknow所说,您可以分配新的实体来解决问题。
My answer will help you to understand what went wrong & correcting it. Like Nicknow said, you can assign fresh entity to solve issue.
这篇关于Dynamics CRM SDK:批量更新实体中的特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!