【问题标题】:Can I update the owner id of a Contact using LINQ?我可以使用 LINQ 更新联系人的所有者 ID 吗?
【发布时间】:2011-12-06 11:00:42
【问题描述】:

我正在使用 CRM 2011,并尝试使用此代码更新联系人的 OwnerId:

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")?如果是这样,这是在哪里记录的,以便我知道我无法更新哪些其他属性?

【问题讨论】:

    标签: linq dynamics-crm-2011


    【解决方案1】:

    无法通过更新来修改记录的所有者。您必须改为发送AssignRequest

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

    【讨论】:

    • 是否有需要特定请求对象的其他属性列表,或者只有所有者?
    • 状态是另一个状态 - 我认为 CRM 为每个实体生成两个类,模式为 SetStateAccountRequest 和 SetStateAccountResponse。
    • 像往常一样,失败时 SDK 不会发出警告。
    • @Ryan 它只是被过滤掉了,因为所有者不是 可更新 字段
    猜你喜欢
    • 2011-10-01
    • 1970-01-01
    • 2012-11-28
    • 2016-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    相关资源
    最近更新 更多