Dynamics CRM 2015/2016 Web API:新的数据查询方式
2023-09-11 14:14:09 时间
今天我们来看看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,博主将在兴许的博文中为大家介绍它的用法。
相关文章
- [web前端] npm install -save 和 -save-dev 傻傻分不清
- 【CTF WEB】ISCC 2016 web 2题记录
- Web 开发中 20 个很有用的 CSS 库 - WEB开发者
- loadrunner12.55:常用函数汇总说明之Web Vuser Functions(WEB)参数函数
- 配置K8S web ui控制台
- 请说明一下web.xml文件中可以配置哪些内容?
- 转:Java Web应用中调优线程池的重要性
- 如何在 Web 应用里消费 SAP Leonardo 的机器学习 API
- Atitit 数据出入管理法v3 目录 1.1. 边界检查:web边界和sql边界1 2. 检查条目1 2.1. 数据种类检查 整数 小数 字符串(带长度,字符白名单校验)1 2.2. 字符黑
- Atitit 前端测试最简化内嵌web服务器 php 与node.js 目录 1.1. php内置Web Server1 1.2. Node的2 Node的比较麻烦些。。Php更加简单
- paip.web数据绑定 下拉框的api设计 选择框 uapi python .net java swing jsf总结
- web强签名正常:Spire.Office Platinum(NET) 7.10.0
- Stimulsoft Dashboards.WEB 2022.2.3 Crack
- ASP.NET Web Forms - 数据绑定
- python web py入门(63)- jQuery - 判断浏览器窗口是否发生改变
- python web py入门(35)- 通过窗口让用户输入数据
- 网站后台返回xml,json格式的数据,编码和格式问题(web.py)
- 当深度学习遇上Web开发:Spring和OpenAI如何实现图片生成?
- ASP.NET WEB+EntityFramework数据持久化——考核练习库——1、用户管理系统(考点:查询列表、增加、删除)
- 【Web开发】Vue2.0数据去重&Element-UI单选框
- Web前端性能优化_图层与重绘重排