0

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

属性“sgfdhr_leavetype.new_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 = _orgService.RetrieveMultiple(GetLeavedetails);”的错误 上面代码中的这一行。

谢谢,

4

1 回答 1

0

The error is pretty clear you have this condition:

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

The error is telling you that LeaveManagement["new_leavedetails"] is an EntityReference (lookup) and not a Guid

You can cast the field before and after put the Id inside the condition:

EntityReference detailsRef = (EntityReference)LeaveManagement["new_leavedetails"];
GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, detailsRef.Id);
于 2014-09-19T14:23:59.640 回答