CRM多表链接查询+分页

 ConditionExpression condition2 = new ConditionExpression();
            condition2.AttributeName = "accountcategorycode";
            condition2.Operator = ConditionOperator.Equal;
            condition2.Values.Add(0);
            ConditionExpression condition3 = new ConditionExpression();
            condition3.AttributeName = "name";
            condition3.Operator = ConditionOperator.Like;
            condition3.Values.Add("%" + txtKeyWord.Text.Trim() + "%");
            ConditionExpression condition6 = new ConditionExpression();
            condition6.AttributeName = "parentaccountid";
            condition6.Operator = ConditionOperator.Null;
            FilterExpression filter1 = new FilterExpression();
            filter1.Conditions.Add(condition2);
            if (txtKeyWord.Text.Trim().Length > 0)
            {
                filter1.Conditions.Add(condition3);
            }
            if (cbxaccount.Checked == true)
            {
                filter1.Conditions.Add(condition6);
            }
            FilterExpression filter2 = new FilterExpression(LogicalOperator.Or);
            ConditionExpression condition4 = new ConditionExpression();
            condition4.AttributeName = "crm_is_group";
            condition4.Operator = ConditionOperator.Null;
            ConditionExpression condition5 = new ConditionExpression();
            condition5.AttributeName = "crm_is_group";
            condition5.Operator = ConditionOperator.Equal;
            condition5.Values.Add(100000001);
            filter2.Conditions.Add(condition4);
            filter2.Conditions.Add(condition5);
            QueryExpression query = new QueryExpression("account");
            query.ColumnSet.AddColumns("accountid", "name", "crm_cust_state", "crm_cust_certtype", "crm_cust_certno", "telephone1", "fax", "telephone3", "emailaddress1", "fax", "parentaccountid");
            query.Criteria.AddFilter(filter1);
            query.Criteria.AddFilter(filter2);

            LinkEntity linkEntity = new LinkEntity("account", "crm_tradeaccount", "accountid", "crm_account", JoinOperator.Inner);
            ConditionExpression conLink = new ConditionExpression();
            conLink.AttributeName = "crm_distributor_netcode";
            conLink.Operator=ConditionOperator.Equal;
            conLink.Values.Add(_distributor_netcode);
            linkEntity.LinkCriteria.AddCondition(conLink);
            query.LinkEntities.Add(linkEntity);
            query.Distinct = true;

            query.AddOrder("name", OrderType.Ascending);

query.PageInfo
= new PagingInfo(); query.PageInfo.Count = GridView1.PageSize; query.PageInfo.PageNumber = (GridView1.PageIndex + 1); query.PageInfo.PagingCookie = null; query.PageInfo.ReturnTotalRecordCount = true; Method method = new Method();//OrganizationServiceProxy或者IOrganizationService类型对象 EntityCollection entitys = method.RetrieveMultiple(query);

 

posted @ 2013-08-21 12:20  刘满意  阅读(1034)  评论(0编辑  收藏  举报