Tuesday, November 12, 2019

Complext Query Expression


Complex Query Expression.

In this post , we will see about the code for complex query expression

 int pageNumber = 1;
            int recordCount = 0;
            int notAddedRecord = 0;
            string pagingCookie = null;

            EntityCollection Accountitem= new EntityCollection();
            EntityCollection Accountlist= new EntityCollection();
           
            try
            {
                do
                {
                                    
                    QueryExpression accountdetail= new QueryExpression("Account")
                    {
                        NoLock = true,                       
                        ColumnSet = new ColumnSet(new string[] { "name""accountnumber","primarycontact"}),
                        LinkEntities =
                            {
                                new LinkEntity
                                {
                                    JoinOperator = JoinOperator.Inner,
                                    LinkFromEntityName= "account",
                                    LinkFromAttributeName = "primarycontact",
                                    LinkToEntityName= "contact",
                                    LinkToAttributeName= "contactid",
                                    Columns = new ColumnSet(new string[] {"contactname"}),
                                    LinkCriteria =
                                    {
                                        Conditions =
                                        {
                                            new ConditionExpression("contactname"ConditionOperator.Equal , "TestContact"),
                                            new ConditionExpression("statuscode"ConditionOperator.In,1,2),
                                        }
                                    },
                                    EntityAlias = "case",
                                },

                                                                      
                      
                        PageInfo = new PagingInfo()
                        {
                            Count = 5000,
                            PageNumber = pageNumber,
                            PagingCookie = pagingCookie
                        },
                        Criteria = new FilterExpression()
                        {
                            Filters =
                            {
                                new FilterExpression
                                {
                                    FilterOperator = LogicalOperator.And,
                                    Conditions =
                                    {
                                        new ConditionExpression("contactname"ConditionOperator.NotNull),
                                        new ConditionExpression("statuscode"ConditionOperator.In,1,2),
                                    },
                                },
                            }
                        }
                    };
                    Accountitem= organizationService.RetrieveMultiple(accountdetail);
                 
                        TraceTextLog("Total Count is: " + Accountitem.Entities.Count);
                    Accountlist.Entities.AddRange(Accountitem.Entities);

                    pageNumber++;
                        pagingCookie = Accountitem.PagingCookie;
                   
                }
                while (Accountitem.MoreRecords);

               

                if (Accountlist.Entities.Count > 0)
                {
                       // do the logic if record exist
                   
                  }
            }




No comments:

Post a Comment