[英]Update only some fields in a Microsoft Dynamics entity
我正在用 C# 语言开发一个软件,它通过调用组织服务与 Microsoft Dynamics 交互。
我只需要更新实体的某些字段,但是当我调用更新操作时,Microsoft Dynamics 会启动对实体所有字段的大规模更新。 我不想要这种大规模更新,我只需要更新 2 或 3 个字段。
这是我的代码:
//reading account
Entity account = <reading entity with a call to organizationService>
//update fields
account["fieldName1"] = newValue;
account["fieldName2"] = newValue2;
//call to update entity
organizationService.Update(account);
我该如何解决这个问题?
我们在这里使用早期绑定,我们也接受整个对象将被更新,但从内存中:试试这个
var accountToBeSentToDynamics = new Entity("account");
accountToBeSentToDynamics.Id = accountToBeUpdated.Id;
accountToBeSentToDynamics["name"] = "Only This Field will be updated";
我们还将这些添加到插入或更新列表中,并以 1000 或更小的批量刷新它们以提高性能
这是你的问题。
Entity account = <reading entity with a call to organizationService>;
在对组织服务的调用中检索到的任何属性都将出现在您的“帐户”对象中,并随后在更新消息中重新发送到 CRM。
尝试这样的事情:
Entity retrieved = <reading entity with a call to organizationService>;
Entity account = new Entity("account", retrieved.Id);
//update fields
account["fieldName1"] = newValue;
account["fieldName2"] = newValue2;
//call to update entity
organizationService.Update(account);
这样您就可以保证在 CRM 中只更新您添加到对象的属性。
最后,最佳实践是在执行 Retrieve 或 RetrieveMultiple 时仅检索执行业务逻辑所需的属性。 更多的属性会降低查询的性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.