我可以使用LINQ更新联系人的所有者ID吗? [英] Can I update the owner id of a Contact using LINQ?
问题描述
我正在使用CRM 2011,并尝试使用以下代码更新联系人的OwnerId:
I'm using CRM 2011, and attempting to update the OwnerId of contact using this code:
var crmContext = new CustomCrmContext(service);
var contact = crmContext.Contact.FirstOrDefault(c=>c.Id == id);
contact.OwnerId.Id= newOwnerId;
crmContext.UpdateObject(contact);
crmContext.SaveChanges();
我没有收到任何错误,但是ownerId从未在数据库中更新.我可以更新其他属性,但我只是想知道OwnerId是否特殊,您是否必须使用OrganizationRequest("Assign")?如果是这样,该文件记录在哪里,以便我知道我无法更新哪些其他属性?
I don't get any errors, however, the ownerId never updates in the database. I am able to update other attributes, but I'm just wondering if maybe the OwnerId is special and you have to use OrganizationRequest("Assign")? If so, where is this documented so I know what other attributes I cannot update?
推荐答案
记录的所有者无法通过更新进行修改.您必须发送 AssignRequest .
The owner of a record cannot be modified with an update. You have to send a AssignRequest instead.
// Create the Request Object and Set the Request Object's Properties
var request = new AssignRequest
{
Assignee = new EntityReference(SystemUser.EntityLogicalName, _newOwnerId),
Target = new EntityReference(Account.EntityLogicalName, _accountId)
};
// Execute the Request
_service.Execute(request);
这篇关于我可以使用LINQ更新联系人的所有者ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!