3

我目前正在尝试检索分配给特定安全角色分配给具有安全角色的团队的所有系统用户。在构建查询时,似乎只在以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我的问题:有没有办法对两个链接实体应用过滤器?

我找到了一种解决方法,使用两个 fetch 表达式查询,然后合并两个结果并进行不同的计数,但我只是好奇查询表达式中是否有一种方法可以在一个查询中执行此操作。

4

1 回答 1

3

不,不可能将LinkEntity连接包装在FilterExpression.

事实上,关于链接实体的过滤能力QueryExpression是相当有限的。例如,您不能查询没有特定实体类型的相关记录的记录。

于 2017-04-21T13:15:05.287 回答