我的代码中收到以下错误:
属性'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);”的错误以上代码中的这一行。
谢谢,
答案 0 :(得分:0)
错误很清楚你有这个条件:
GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, LeaveManagement["new_leavedetails"]);
错误告诉您LeaveManagement["new_leavedetails"]
是EntityReference
(查询),而不是Guid
您可以在Id
置于条件之前和之后投射该字段:
EntityReference detailsRef = (EntityReference)LeaveManagement["new_leavedetails"];
GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, detailsRef.Id);