Dynamics CRM 2015/2016 Web API:新的数据查询方式
来源:互联网 发布:艾克里里の淘宝店 编辑:程序博客网 时间:2024/05/16 14:22
今天我们来看看Web API的数据查询功能,虽然之前介绍CRUD的文章里面提到过怎么去Read数据,但是并没有详细的去深究那些细节,今天我们就来具体看看吧。其实呢,Web API的数据查询接口也是基于OData协议的,所以之前的OData Url Query的构造规则没有很大的变化,例如:$top, $select, $filter, $expand, $order的功能还是在的,不过也添加了一些新东西,例如
$count -- 返回记录的总数
Paging Mechanism(分页机制)-- 来东西,现在,实现机制不一样了,基于HTTP报头设置页大小
Formatted Value(新东西,没有找到最新的文档) -- 目测和记录的格式化有关,不过没找到具体的Mapping文档
$count
$count很好理解,返回记录在系统中的总数(和filter条件相关),如果不制定filter条件,则返回所有记录的总数。
Paging Mechanism
需要设置HTTP 报头:odata.maxpagesize=?,和之前的API不一样了HttpRequestMessage retrieveAccReq = new HttpRequestMessage(HttpMethod.Get, webApiUrl + "/accounts?$select=name&$count=true"); retrieveAccReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessCode); retrieveAccReq.Headers.Add("Prefer", "odata.maxpagesize=2"); string nextPageLink = string.Empty; JObject result = null; int pageIndex = 1; HttpResponseMessage retrieveAccResp; do { if (!string.IsNullOrWhiteSpace(nextPageLink)) { retrieveAccReq = new HttpRequestMessage(HttpMethod.Get, nextPageLink); retrieveAccReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessCode); retrieveAccReq.Headers.Add("Prefer", "odata.maxpagesize=2"); } retrieveAccResp = await client.SendAsync(retrieveAccReq); result = JsonConvert.DeserializeObject<JObject>(await retrieveAccResp.Content.ReadAsStringAsync()); Console.WriteLine("Page-" + pageIndex++); Console.WriteLine(result.ToString()); if (retrieveAccResp.IsSuccessStatusCode) { if (result["@odata.nextLink"] != null && !string.IsNullOrWhiteSpace(result["@odata.nextLink"].Value<string>())) { nextPageLink = result["@odata.nextLink"].Value<string>(); } else { nextPageLink = ""; } } else { break; } } while (!string.IsNullOrEmpty(nextPageLink));
Formatted Value
目测和返回记录的格式化有关,返回的记录更好理解,不过没找到具体的Formatted Mapping,建议不轻易使用。
HttpRequestMessage retrieveAccWithFormattedValueReq = new HttpRequestMessage(HttpMethod.Get, webApiUrl + "/accounts?$select=name,donotpostalmail,accountratingcode,numberofemployees,revenue&$top=1"); retrieveAccWithFormattedValueReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessCode); retrieveAccWithFormattedValueReq.Headers.Add("Prefer", " odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\""); HttpResponseMessage retrieveAccWithFormatedValueResp = await client.SendAsync(retrieveAccWithFormattedValueReq); if (retrieveAccWithFormatedValueResp.IsSuccessStatusCode) { JObject result = JsonConvert.DeserializeObject<JObject>(await retrieveAccWithFormatedValueResp.Content.ReadAsStringAsync()); Console.WriteLine(result.ToString()); }
在Web API的数据查询里面呢,还有一个比较重要的只是就是使用Web API Query Function,博主将在后续的博文中为大家介绍它的使用方法。
0 0
- Dynamics CRM 2015/2016 Web API:新的数据查询方式
- Dynamics CRM 2015/2016 Web API:基于视图的数据查询
- Dynamics CRM 2015/2016 Web API:聚合查询
- Dynamics CRM 2015/2016 Web API:简介
- Dynamics CRM 2015/2016 Web API:验证和授权
- Dynamics CRM 2015/2016/365 Web API:用户模拟
- Dynamics CRM 2016 Web API 消息列表
- Dynamics CRM 2015/2016 Web API:注册 APP(调用CRM Online Web API)
- Dynamics CRM 2015/2016 Web API:重客户端的CRUD操作
- Dynamics CRM 2015/2016 Web API:Unbound Function 和 Bound Function
- Dynamics CRM 2015/2016 Web API:Unbound Action 和 Bound Action
- Dynamics CRM 2015/2016 Web API:Unbound Custom Action 和 Bound Custom Action
- Dynamics CRM2016 Web Api之根据时间查询数据
- Microsoft Dynamics CRM 4.0的新特性
- Dynamics 365Online 查询Web Api的请求WebUri
- Dynamics CRM 通过OData查询数据URI中包含中文的情况
- Dynamics CRM2016 Web Api之分页查询
- Dynamics CRM 构建IN查询
- python 正则表达式
- POJ 1797 - Heavy Transportation
- java中最常用的类
- 【niubi-job——一个开源的分布式任务调度框架】-----安装教程
- Object-C--->Swift之(十)存储属性
- Dynamics CRM 2015/2016 Web API:新的数据查询方式
- java的8种基础数据类型
- POJ 3268 - Silver Cow Party
- Android-夜间模式最佳实践
- 【niubi-job——一个分布式的任务调度框架】----如何开发一个niubi-job的定时任务
- 互联网推荐系统的比较研究
- Dynamics CRM 2015/2016 Web API:基于视图的数据查询
- react-native之native主动向js发送事件
- Hbase基础操作