动态 CRM:需要通过 API 更新连接实体

Dynamic CRM : Need to update Connection entities via API

我已经通过以下代码通过 API 创建了连接(Dynamics Crm: creating Connection entities via API

Entity connection = new Entity("connection");
connection["record1id"] = new EntityReference("contact", someContactId);
connection["record1objecttypecode"] = new OptionSetValue(2);
connection["record1roleid"] = new EntityReference("connectionrole",    someConnectionRoleId);
connection["record2id"] = new EntityReference("incident", someCaseId);
connection["record2objecttypecode"] = new OptionSetValue(122);
connection["record2roleid"] = new EntityReference("connectionrole", someOtherConnectionRoleId);
var newId = service.Create(connection);

问题:我需要更新两条记录之间的连接角色。

如果我理解正确,你只需要沿着同一条路前进,使用从Create中获得的Id来引用记录:

// Your code
Entity connection = new Entity("connection");
connection["record1id"] = new EntityReference("contact", someContactId);
connection["record1objecttypecode"] = new OptionSetValue(2);
connection["record1roleid"] = new EntityReference("connectionrole",    someConnectionRoleId);
connection["record2id"] = new EntityReference("incident", someCaseId);
connection["record2objecttypecode"] = new OptionSetValue(122);
connection["record2roleid"] = new EntityReference("connectionrole", someOtherConnectionRoleId);
var newId = service.Create(connection);

// And then ...

connection = new Entity("connection"); // start from scratch
connection["connectionid"] = newId; // needed for the CRM to know what to update
connection["record1roleid"] = new EntityReference("connectionrole",    yetAnotherConnectionRoleId);
connection["record2roleid"] = new EntityReference("connectionrole", yetAnotherAnotherConnectionRoleId);

service.Update(connection);