Can I update the owner id of a Contact using LINQ?

有些话、适合烂在心里 提交于 2019-11-27 06:11:02

问题


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();

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?


回答1:


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);


来源:https://stackoverflow.com/questions/7746046/can-i-update-the-owner-id-of-a-contact-using-linq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!