zoukankan      html  css  js  c++  java
  • CRM 2011 fetchxml查询取超过5千笔

     protected void loadUnTaskInfo(IOrganizationService server)
        {
            string untaskXml = string.Format(@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                                <entity name='task'>
                                                <attribute name='activityid' />
                                                <attribute name='subject' />
                                                <attribute name='new_prioritylevel' />
                                                <attribute name='regardingobjectid' />
                                                <attribute name='scheduledstart' />
                                                <attribute name='scheduledend' />
                                                <attribute name='ownerid' />
                                                <order attribute='createdon' descending='true' />
                                                <filter type='and'>
                                                    <condition attribute='statecode' operator='eq' value='0' />
                                                </filter>
                                                <link-entity name='systemuser' from='systemuserid' to='owninguser' visible='false' link-type='outer' alias='users'>
                                                    <attribute name='businessunitid' />
                                                </link-entity>
                                                </entity>
                                            </fetch>");
    
            int fetchCount = 300; //定义每页查询的结果数
            int pageNumber = 1;
            string pagingCookie = null;
    
    string  landname = “”;
            while (true)
            {
                string xml = CreateXml(untaskXml, pagingCookie, pageNumber, fetchCount);
                EntityCollection returnCollection = server.RetrieveMultiple(new Microsoft.Xrm.Sdk.Query.FetchExpression(xml));
    
                foreach (var untask in returnCollection.Entities)
                {               landname = (untask.Contains("new_landname")) ? untask.Attributes["new_landname"].ToString() : "";
                }
    
                if (returnCollection.MoreRecords)
                {
                    pageNumber++;
                }
                else
                {
                    break;
                }
            }
    }
    
    
        public string CreateXml(string xml, string cookie, int page, int count)
        {
            StringReader stringReader = new StringReader(xml);
            XmlTextReader reader = new XmlTextReader(stringReader);
    
            // Load document
            XmlDocument doc = new XmlDocument();
            doc.Load(reader);
    
            return CreateXml(doc, cookie, page, count);
        }
    
        public string CreateXml(XmlDocument doc, string cookie, int page, int count)
        {
            XmlAttributeCollection attrs = doc.DocumentElement.Attributes;
    
            if (cookie != null)
            {
                XmlAttribute pagingAttr = doc.CreateAttribute("paging-cookie");
                pagingAttr.Value = cookie;
                attrs.Append(pagingAttr);
            }
    
            XmlAttribute pageAttr = doc.CreateAttribute("page");
            pageAttr.Value = System.Convert.ToString(page);
            attrs.Append(pageAttr);
    
            XmlAttribute countAttr = doc.CreateAttribute("count");
            countAttr.Value = System.Convert.ToString(count);
            attrs.Append(countAttr);
    
            StringBuilder sb = new StringBuilder(1024);
            StringWriter stringWriter = new StringWriter(sb);
    
            XmlTextWriter writer = new XmlTextWriter(stringWriter);
            doc.WriteTo(writer);
            writer.Close();
    
            return sb.ToString();
  • 相关阅读:
    (4.7)怎么捕获和记录SQL Server中发生的死锁?
    SQLSERVER排查CPU占用高的情况
    (4.6)sql server索引缺失提示
    (4.14)向上取整、向下取整、四舍五入取整的实例
    mysql大致学习路径
    (2)linux未使用eth0,未使用IPV4导致无法连接
    (4.13)sql server参数嗅探(parameter sniffing)
    完美女人
    关于box-sizing
    什么是担当
  • 原文地址:https://www.cnblogs.com/z1984/p/3161234.html
Copyright © 2011-2022 走看看