通过fetchXml 实现分页查询
来源:互联网 发布:神雕群芳谱知乐改编 编辑:程序博客网 时间:2024/06/05 02:42
///
/// 实现分页查询
///
/// 页数
/// 每页大小
/// 是否成功
public string GetEntityList( IOrganizationService crmService, int page, int size)
{
String fetchXml = @”标准fetch查询,奇葩的是粘贴到这里之后竟然不能显示”;
//解析Xml并分页后返回Json
String retValue = GetDateByFetchXml(crmService, fetchXml, page, size);
return retValue;
}
以下方法是SDK中的标准方法:
#region 通过FetchXml查询数据
///
/// 通过FetchXml查询数据
///
/// OrgService
/// 查询FetchXml
/// 页码
/// 每页记录数
/// JsonString
public string GetDateByFetchXml(IOrganizationService _service, string fetchXml, int pageNumber, int pageSize)
{
// Specify the current paging cookie. For retrieving the first page,
// pagingCookie should be null.
string pagingCookie = null;
// Build fetchXml string with the placeholders. string xml = CreateXml(fetchXml, pagingCookie, pageNumber, pageSize); // Excute the fetch query and get the xml result. RetrieveMultipleRequest fetchRequest1 = new RetrieveMultipleRequest { Query = new FetchExpression(xml) }; EntityCollection returnCollection = ((RetrieveMultipleResponse)_service.Execute(fetchRequest1)).EntityCollection; string jsonString = JsonConvert.SerializeObject(returnCollection); return jsonString; } private 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); } private 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(); }
- 通过fetchXml 实现分页查询
- fetchxml分页和QueryExpression分页
- Mybatis通过拦截器实现分页查询
- 通过sql语句查询实现分页
- crm使用FetchXml聚合查询
- 在SQL Server中通过SQL语句实现分页查询
- 在SQL Server中通过SQL语句实现分页查询
- 通过bboss persistent框架实现数据库分页查询功能
- 在SQL Server中通过SQL语句实现分页查询
- 在SQL Server中通过SQL语句实现分页查询
- 在SQL Server中通过SQL语句实现分页查询
- CRM2011 将Query查询转化为FetchXml
- crm2011 将FetchXml查询转化为Query
- crm使用FetchXml分组聚合查询
- 通过查询结果进行分页
- 通过rownum实现分页
- 通过servlet实现分页
- Hibernate 实现分页查询
- Vim命令合集(貌似有的有错误,Mark在这里,用到的时候来找)
- SpringMVC框架介绍
- 运行程序报错:the file"xxx"couldn't be open because you don't have permisslion to view it
- Objective-C 【在手动内存管理中如何写set方法】
- 【java】getAbsolutePath()方法详解
- 通过fetchXml 实现分页查询
- 干货分享!不得不看的【7年竞价实战经验总结】
- Linux系统下如何做到SSH免密码登录
- iOS UITableView显示下移问题:automaticallyAdjustsScrollViewInsets 属性浅谈
- kafka参数详解
- 天声人語
- Android不透明度16进制值
- 背景建模-均值法(Matlab)高斯背景建模(opencv)
- 如何把ppt幻灯片转成pdf文档