1
QueryExpression Query = new QueryExpression { EntityName = "incident", ColumnSet = new ColumnSet(true) };

            LinkEntity CustomerEntity = new LinkEntity
            {
                LinkFromEntityName = "incident",
                LinkToEntityName = "account",
                LinkFromAttributeName = "customerid",
                LinkToAttributeName = "accountid",
                EntityAlias = "Customer",
                Columns = new ColumnSet("den_firstname", "den_lastname")
            };

            LinkEntity SubSubTypeEntity = new LinkEntity
            {
                LinkFromEntityName = "incident",
                LinkToEntityName = "den_subsubtype",
                LinkFromAttributeName = "den_subsubtypeid",
                LinkToAttributeName = "den_subsubtypeid",
                JoinOperator = JoinOperator.Inner,
                EntityAlias = "SubSubType",
                Columns = new ColumnSet("den_resolvedby")
            };

            Query.ColumnSet = new ColumnSet(true);

            Query.LinkEntities.Add(CustomerEntity);
            Query.LinkEntities.Add(SubSubTypeEntity);

            if (SRStatus > 0)
                Query.Criteria.AddCondition("statuscode", ConditionOperator.Equal, SRStatus);
            if (ResolutionType > 0)
                Query.Criteria.AddCondition("den_roltype", ConditionOperator.Equal, ResolutionType);

            CustomerEntity.LinkCriteria.AddCondition("den_lcouserid", ConditionOperator.Equal, lconameId);

            FilterExpression childFilter = Query.Criteria.AddFilter(LogicalOperator.Or);
            FilterExpression custFilter = CustomerEntity.LinkCriteria.AddFilter(LogicalOperator.Or);

            if (!string.IsNullOrEmpty(SearchText))
            {
                childFilter.AddCondition("den_userid", ConditionOperator.Equal, SearchText);
                childFilter.AddCondition("ticketnumber", ConditionOperator.Like, "%" + SearchText + "%");
                childFilter.AddCondition("title", ConditionOperator.Equal, SearchText);

//下面的代码正在产生问题,如果我删除它,它会起作用并且我得到结果。但我需要添加两个过滤器

                custFilter.AddCondition("name", ConditionOperator.Equal, SearchText);
                custFilter.AddCondition("den_firstname", ConditionOperator.Equal, SearchText);
                //custFilter.AddCondition("den_lastname", ConditionOperator.Equal, SearchText);
                custFilter.AddCondition("emailaddress1", ConditionOperator.Equal, SearchText);
                custFilter.AddCondition("telephone1", ConditionOperator.Equal, SearchText);
            }

如果我使用 custFilter 或 childFilter 删除所有条件,我会得到结果,但是当我同时保留这两个条件时,它会返回任何结果(无错误)。

4

1 回答 1

0

下面的调整解决了我的问题。

QueryExpression Query = new QueryExpression { EntityName = "incident", ColumnSet = new ColumnSet(true) };

            LinkEntity CustomerEntity = new LinkEntity
            {
                LinkFromEntityName = "incident",
                LinkToEntityName = "account",
                LinkFromAttributeName = "customerid",
                LinkToAttributeName = "accountid",
                EntityAlias = "Customer",
                Columns = new ColumnSet("den_firstname", "den_lastname", "name", "accountid", "emailaddress1", "telephone1", "den_lcouserid"),
                JoinOperator = JoinOperator.Inner
            };
            CustomerEntity.LinkCriteria.AddCondition("den_lcouserid", ConditionOperator.Equal, lconameId);

            LinkEntity SubSubTypeEntity = new LinkEntity
            {
                LinkFromEntityName = "incident",
                LinkToEntityName = "den_subsubtype",
                LinkFromAttributeName = "den_subsubtypeid",
                LinkToAttributeName = "den_subsubtypeid",
                JoinOperator = JoinOperator.Inner,
                EntityAlias = "SubSubType",
                Columns = new ColumnSet("den_resolvedby")
            };            

            Query.LinkEntities.Add(CustomerEntity);
            Query.LinkEntities.Add(SubSubTypeEntity);                             

            FilterExpression incidentChildFilterOR = Query.Criteria.AddFilter(LogicalOperator.Or);
            FilterExpression incidentChildFilterAND = Query.Criteria.AddFilter(LogicalOperator.And);
            FilterExpression customerChildFilterOR = CustomerEntity.LinkCriteria.AddFilter(LogicalOperator.Or);

            if (SRStatus > 0)
                incidentChildFilterAND.AddCondition("statuscode", ConditionOperator.Equal, SRStatus);
            if (ResolutionType > 0)
                incidentChildFilterAND.AddCondition("den_roltype", ConditionOperator.Equal, ResolutionType);  

            if (!string.IsNullOrEmpty(SearchText))
            {
                if (SRStatus > 0)
                    incidentChildFilterOR.AddCondition("statuscode", ConditionOperator.Equal, SRStatus);
                if (ResolutionType > 0)
                    incidentChildFilterOR.AddCondition("den_roltype", ConditionOperator.Equal, ResolutionType); 

                incidentChildFilterOR.AddCondition("den_userid", ConditionOperator.Equal, SearchText);
                incidentChildFilterOR.AddCondition("ticketnumber", ConditionOperator.Like, "%" + SearchText + "%");
                incidentChildFilterOR.AddCondition("title", ConditionOperator.Equal, SearchText);


                customerChildFilterOR.AddCondition("name", ConditionOperator.Equal, SearchText);
                customerChildFilterOR.AddCondition("den_firstname", ConditionOperator.Equal, SearchText);
                customerChildFilterOR.AddCondition("den_lastname", ConditionOperator.Equal, SearchText);
                customerChildFilterOR.AddCondition("emailaddress1", ConditionOperator.Equal, SearchText);
                customerChildFilterOR.AddCondition("telephone1", ConditionOperator.Equal, SearchText);
            }
于 2015-05-07T05:00:59.850 回答