Dynamics crm 2011 接收工作流活动代码中的错误

Dynamics crm 2011 接收工作流活动代码中的错误,dynamics-crm-2011,workflow-activity,query-expressions,Dynamics Crm 2011,Workflow Activity,Query Expressions,我收到代码中的以下错误: 属性“sgfdhr\u leavetype.new\u employeeleavecalculation”的条件:应为“System.Guid”类型的参数,但收到“Microsoft.Xrm.Sdk.EntityReference” 我的代码如下: public int Getleavetype(Entity LeaveManagement, IOrganizationService _orgService, CodeActivityContext Acontext)

我收到代码中的以下错误:

属性“sgfdhr\u leavetype.new\u employeeleavecalculation”的条件:应为“System.Guid”类型的参数,但收到“Microsoft.Xrm.Sdk.EntityReference”

我的代码如下:

public int Getleavetype(Entity LeaveManagement, IOrganizationService _orgService, CodeActivityContext Acontext)
        {
      QueryExpression GetLeavedetails = new QueryExpression();
      GetLeavedetails.EntityName = "sgfdhr_leavetype";
      GetLeavedetails.ColumnSet = new ColumnSet("new_type");
      GetLeavedetails.ColumnSet = new ColumnSet("new_availabledays");
      GetLeavedetails.Criteria.AddCondition("new_type", ConditionOperator.Equal, 1);
      GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation",    ConditionOperator.Equal,LeaveManagement["new_leavedetails"]);
            EntityCollection LeaveDetails = _orgService.RetrieveMultiple(GetLeavedetails);
            return (int)LeaveDetails[0]["new_availabledays"];
        }
在上面的代码中,我收到了“EntityCollection LeaveDetails=\u orgService.RetrieveMultiple(GetLeavedetails);”这一行的错误


谢谢,

错误很明显,您有以下情况:

 GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, LeaveManagement["new_leavedetails"]);
EntityReference detailsRef = (EntityReference)LeaveManagement["new_leavedetails"];
GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, detailsRef.Id);
该错误告诉您,
LeaveManagement[“new\u leavedetails”]
是一个
EntityReference
(查找)而不是
Guid

您可以在将
Id
放入条件之前和之后强制转换字段:

 GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, LeaveManagement["new_leavedetails"]);
EntityReference detailsRef = (EntityReference)LeaveManagement["new_leavedetails"];
GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, detailsRef.Id);