簡體   English   中英

僅更新 Microsoft Dynamics 實體中的某些字段

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM