CRMWebAPI - 如何使用实体参考?

CRMWebAPI - How to work with Entity reference?

我将 CRMWebAPI 用于 CRM 的 CRUD 操作。我怎样才能在那里使用实体参考?

例如,当我想更新帐户实体上的父帐户属性时,父帐户属性是查找到另一个帐户。

像这样:

dynamic updateObject = new ExpandoObject();
updateObject.parentaccountid = the_entity_reference;
dynamic updateResult = await api.Update("accounts", new Guid("1111111-2222-3333-4444-55555555"), updateObject, false);

Referred this code sample 并能写出这个。请测试一下。

dynamic updateObject = new ExpandoObject();

Guid accountID = new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx");    
var parAcctIndexer = updateObject as IDictionary<string, Object>;
parAcctIndexer["parentaccountid@odata.bind"] = "/accounts(" + accountID.ToString() + ")";

dynamic updateResult = await api.Update("accounts", new Guid("1111111-2222-3333-4444-55555555"), updateObject, false);