Dynamics crm CRM:GetChildren在无子对象上引发异常

Dynamics crm CRM:GetChildren在无子对象上引发异常,dynamics-crm,Dynamics Crm,我们正在使用MSCRM Dynamics,并试图获取特定用户的所有子项。(用户有一个管理器,管理器有“子项”。)下面的操作正常,但如果用户没有子项,则抛出异常。一开始这似乎是合乎逻辑的,但为什么不返回一个空集呢?最重要的是,它抛出一个带有“Invalid Argument”(这是错误的)神秘消息的SoapException,.Detail.InnerText显示“0x80040203传递给ConditionOperator.In的值为空平台”。如果查看相应的响应类,它有一个集合——为什么不将其保

我们正在使用MSCRM Dynamics,并试图获取特定用户的所有子项。(用户有一个管理器,管理器有“子项”。)下面的操作正常,但如果用户没有子项,则抛出异常。一开始这似乎是合乎逻辑的,但为什么不返回一个空集呢?最重要的是,它抛出一个带有“Invalid Argument”(这是错误的)神秘消息的SoapException,.Detail.InnerText显示“0x80040203传递给ConditionOperator.In的值为空平台”。如果查看相应的响应类,它有一个集合——为什么不将其保留为空呢

// Create the request object.
RetrieveAllChildUsersSystemUserRequest retrieve =
    new RetrieveAllChildUsersSystemUserRequest();

// Create the column set object that indicates the fields to be retrieved.
ColumnSet cols = new ColumnSet();
cols.EntityName = "systemuserid";

// Set the column set.
retrieve.ColumnSet = cols;

// Set the ID of the parent user.
retrieve.EntityId = context.UserId;

RetrieveAllChildUsersSystemUserResponse retrieved =
    new RetrieveAllChildUsersSystemUserResponse();

/// Execute the request.
/// Catches if user does not have children
/// (Check to see if user is manager)

try
{
    retrieved =
        (RetrieveAllChildUsersSystemUserResponse)crmService.Execute(retrieve);
}
catch (System.Web.Services.Protocols.SoapException e)
{
    throw new Exception(string.Format("{0}", e.Detail.InnerText));
}

我同意,它可能只会返回一个空结果。我的猜测是,执行请求或准备响应的某个步骤被转换为
QueryExpression
。如果您使用使用
ConditionExpression的
ConditionExpression
,该表达式使用
ConditionOperator.In
并向其传递一个空列表,则QueryExpressions会爆炸。因此,它可能类似于获取子systemuser GUID的列表,在某些情况下是一个空列表,然后尝试使用另一个
QueryExpression
检索该列表中系统用户的所有属性,这就是引发异常的原因


您可能可以自行设计一个
QueryExpression
或FetchXML,以获得相同的结果,而不会在列表为空时引发异常,或者只捕获异常并检查特定的错误代码并将其吞下。

我们目前正在吞下所有SOAPException,我真的觉得这是一个糟糕的解决方案。如果找不到更好的解决方案,我必须仔细研究表达式,看看是否可以更好地隔离这个案例。