无法将GUID保存到microsoft crm实体

时间:2014-04-02 18:50:10

标签: c# dynamics-crm-2011

我将服务声明为:

   protected OrganizationService Service = 
        new OrganizationService(
            new CrmConnection(
                new ConnectionStringSettings(

然后我更新这样的guid字段:

        var query = new QueryExpression("contact");
        query.ColumnSet.AddColumn("contactid");
        query.ColumnSet.AddColumn("parentcustomerid");
        query.Criteria.AddCondition("contactid", ConditionOperator.Like, crmPerson.PersonId);
        var result = Service.RetrieveMultiple(query);
        if (result.Entities.Any())
        {
            var r = result.Entities[0];
            r.Attributes["parentcustomerid"] = crmPerson.OrganizationId;
            Service.Update(r);
        }

执行此操作时出现以下错误(字符串字段似乎有效)

System.ServiceModel.FaultException`1 was unhandled
  HResult=-2146233087
  Message=System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #52B2CA82
  Source=mscorlib

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

parentcustomerid是一个查找字段,您需要使用EntityReference设置值,而不是Guid

r.Attributes["parentcustomerid"] = new EntityReference("account", accountId);