针对两个链接实体的 Dynamics CRM 查询表达式过滤器或条件
Dynamics CRM Query Expression filter or condition against two linked entities
我目前正在尝试检索分配给特定安全角色 或 分配给具有安全角色的团队的所有系统用户。在构建查询时,以这种方式编写查询时,似乎只按 and
条件过滤它们:
QueryExpression RolesQuery = new QueryExpression
{
EntityName = "systemuser",
ColumnSet = new ColumnSet("systemuserid"),
Distinct = true,
Criteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("isdisabled", ConditionOperator.Equal, "0")
}
}
}
},
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "systemuser",
LinkToEntityName = "systemuserroles",
LinkFromAttributeName = "systemuserid",
LinkToAttributeName = "systemuserid",
LinkCriteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("roleid", ConditionOperator.Equal, "00000000-0000-0000-0000-000000000000")
}
}
}
}
},
new LinkEntity
{
LinkFromEntityName = "systemuser",
LinkToEntityName = "teammembership",
LinkFromAttributeName = "systemuserid",
LinkToAttributeName = "systemuserid",
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "teammembership",
LinkToEntityName = "team",
LinkFromAttributeName = "teamid",
LinkToAttributeName = "teamid",
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "team",
LinkToEntityName = "teamroles",
LinkFromAttributeName = "teamid",
LinkToAttributeName = "teamid",
LinkCriteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("roleid", ConditionOperator.Equal, "00000000-0000-0000-0000-000000000000")
}
}
}
}
}
}
}
}
}
}
};
我的问题:有没有办法对两个链接的实体应用 or
过滤器?
我发现了一种解决方法,即使用两个获取表达式查询然后合并两个结果并进行不同的计数,但我只是想知道查询表达式中是否有一种方法可以在一个查询中执行此操作。
不,无法将 LinkEntity
连接包装在 FilterExpression
中。
事实上,对于 link 个实体,QueryExpression
的过滤能力相当有限。例如。您不能查询没有特定实体类型相关记录的记录。
我目前正在尝试检索分配给特定安全角色 或 分配给具有安全角色的团队的所有系统用户。在构建查询时,以这种方式编写查询时,似乎只按 and
条件过滤它们:
QueryExpression RolesQuery = new QueryExpression
{
EntityName = "systemuser",
ColumnSet = new ColumnSet("systemuserid"),
Distinct = true,
Criteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("isdisabled", ConditionOperator.Equal, "0")
}
}
}
},
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "systemuser",
LinkToEntityName = "systemuserroles",
LinkFromAttributeName = "systemuserid",
LinkToAttributeName = "systemuserid",
LinkCriteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("roleid", ConditionOperator.Equal, "00000000-0000-0000-0000-000000000000")
}
}
}
}
},
new LinkEntity
{
LinkFromEntityName = "systemuser",
LinkToEntityName = "teammembership",
LinkFromAttributeName = "systemuserid",
LinkToAttributeName = "systemuserid",
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "teammembership",
LinkToEntityName = "team",
LinkFromAttributeName = "teamid",
LinkToAttributeName = "teamid",
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "team",
LinkToEntityName = "teamroles",
LinkFromAttributeName = "teamid",
LinkToAttributeName = "teamid",
LinkCriteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("roleid", ConditionOperator.Equal, "00000000-0000-0000-0000-000000000000")
}
}
}
}
}
}
}
}
}
}
};
我的问题:有没有办法对两个链接的实体应用 or
过滤器?
我发现了一种解决方法,即使用两个获取表达式查询然后合并两个结果并进行不同的计数,但我只是想知道查询表达式中是否有一种方法可以在一个查询中执行此操作。
不,无法将 LinkEntity
连接包装在 FilterExpression
中。
事实上,对于 link 个实体,QueryExpression
的过滤能力相当有限。例如。您不能查询没有特定实体类型相关记录的记录。