OData 1-4 OData语法(上)

如果眼下提供OData的服务地址是

http://localhost:9527/ODataService.svc

提供的服务内容例如以下所看到的 (提供了一个WagerInformations)

<?

xml version="1.0" encoding="utf-8" standalone="yes" ?

>

<service xml:base="http://localhost:9527/ODataService.svc/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app">

<workspace>

<atom:title>Default</atom:title>

<collection href="WagerInformations">

<atom:title>WagerInformations</atom:title>

</collection>

</workspace>

</service>

1.基础查询

  1)列出全部的WagerInformations

    http://localhost:9527/ODataService.svc/WagerInformations

  2)依照主键查询

    http://localhost:9527/ODataService.svc/WagerInformations(1)

    PS:在.net里面一般使用DataServiceKeyAttribute标识主键

  3)获取某个对象的一个成员

    http://localhost:9527/ODataService.svc/WagerInformations(1)/EventName

    获取主键为1的WagerInformations的EventName属性

  4)假设这个属性还有属性 那么依此类推

    http://localhost:9527/ODataService.svc/WagerInformations(1)/Event/EventDateTime

    另外不要试图获取原始类型的一些属性 - -# 比如返回 String的Length属性

  5) $value 方案3返回对象的一个成员用的是Xml的数据格式.实际上我们非常多时候不须要那么多的标签,仅仅想拿返回值

    那么使用url http://localhost:9527/ODataService.svc/WagerInformations(1)/EventName/$value

    方案3的数据 <?xml version="1.0" encoding="utf-8" standalone="yes" ?> <EventName xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">test 1</EventName>

    方案5的数据 test 1

  6) $filter  条件表达式

    查询EventName 等于 "test 1" 的表达式例如以下

    http://localhost:9527/ODataService.svc/WagerInformations?$filter=EventName  eq 'test 1'

    查询时间:

    

$filter=EventDateTime" style="background-color:inherit; color:rgb(29,88,209)">http://localhost:9527/ODataService.svc/WagerInformations?$filter=EventDateTime eq DateTime'2010-12-21T10:10:19.390625'

    组合查询表达式: and操作

    http://localhost:9527/ODataService.svc/WagerInformations?$filter=(EventDateTime eq DateTime'2010-12-21T10:10:19.390625'
) and (BusinessUnitCode eq '2')

  

下面是运算符列表 

Operator

Description

C#         equivalent

eq

equals

==

ne

not equal

!=

gt

greater than

>

ge

greater than or equal

>=

lt

less than

<

le

less than or equal

<=

and

and

&&

or

or

||

()

grouping

()

OData 1-5 OData语法(下)


7) $expand 包括属性和关系

  如果的WagerInformation拥有一个属性 UserInformation User 表示用户信息,  还有一个属性 IEnumerable<CommonInformation> Commons 表示评论信息

  使用 http://localhost:9527/ODataService.svc/WagerInformations?$expand=User ,Commons

  返回的信息中就会包括相关类 (用于主外键关系)

  - -# 假设不手动指定 而是自己主动关联....那就悲剧了 可能数据库中的全部表都有联系...然后把整个数据库返回.....

  曾经做过非常囧的事情.就是开了级联删除...然后删除了一个非常主要的配置项.....整个数据库基本空了

8) $select 查询字段的列表(和sql中select后面的表达式一样)

  下面url仅仅想返回查询全部信息的EventName属性

  

$select=EventName" style="background-color:inherit; color:rgb(29,88,209)">http://localhost:9527/ODataService.svc/WagerInformations?

$select=EventName  

  假设WagerInformation有一个User属性 其包括一个UserName那么查询username的url例如以下

  http://localhost:9527/ODataService.svc/WagerInformations?$select=User/UserName

9) $count 查询数量

  http://localhost:9527/ODataService.svc/WagerInformations/$count

  返回的是真实数据不包括不论什么修饰 (raw data) 传回的http body中就仅仅有一个 "5"  (不包括引號)

10) $orderby  排序

  下面表达式依照BusinessUnitCode 降序 ,然后 EventName 升序排列

   http://localhost:9527/ODataService.svc/WagerInformations?

$orderby=BusinessUnitCode desc,EventName asc

11) $top

  在10的基础上 假设我仅仅想返回第一条数据 那么例如以下

  http://localhost:9527/ODataService.svc/WagerInformations?

$orderby=BusinessUnitCode desc,EventName asc&$top=1

  这里依旧还是用& 来分隔不同的表达式

12) $skip

  这东西一般和$top配合来分页

  下面表达式跳过第一条, 然后返回最多10条数据

  http://localhost:9527/ODataService.svc/WagerInformations?$top=10&$skip=1

13) $inlinecount

  在分页取数据的时候,常常要同一时候统计总记录数

  下面表达式在返回分页数据的同一时候,顺便同一时候返回全部的记录数

  http://localhost:9527/ODataService.svc/WagerInformations?

$top=2&$skip=2&$inlinecount=allpages

  假设表达式中有$filter  条件表达式 ,那么返回的就是符合条件的全部数据的数量

  http://localhost:9527/ODataService.svc/WagerInformations?$filter=BusinessUnitCode eq '1'&$inlinecount=allpages

14) $skiptoken

  比如游标或者书签的一个东西

15)$links

  获取相关实体的url 

  http://localhost:9527/ODataService.svc/WagerInformations(1)/$links/User

16)$metadata

  显示元数据

  http://localhost:9527/ODataService.svc/$metadata

200(OK)

202(Accepted)

204(No Content)

400(Bad Request)

404(Not Found)

405(Method Not Supported)

412(Precondition Failed)

500(Internal Server Error)

版权声明:本文博客原创文章。博客,未经同意,不得转载。

OData语法的更多相关文章

  1. Dynamics 365 We API ODATA语法根据父记录查询子记录,根据子记录查询父记录(附上根据团队,队列名称查成员)

    微软动态CRM专家罗勇 ,回复333或者20190508可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me! 先举个N:N关系的例子.这里以根据团队的名称查找其所有团队成员的 ...

  2. Asp.Net Web API 2第十八课——Working with Entity Relations in OData

    前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyok/p/3446289.html. 本文的示例代码的下载地址 ...

  3. mvc api odata 查询选项之 $inlinecount ,$format 选项

    网上百度“odata 语法”会出来很多结果,其中有一项是比较一致的,那就是odata支持一下几种语法: $filter  条件表达式 -- 对应sql语句的where条件查询,如:/Categorie ...

  4. Working with Entity Relations in OData

    Working with Entity Relations in OData 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs. ...

  5. mvc api odata查询选项之 $inlinecount $format 选项(转)

    出处:http://www.it165.net/pro/html/201505/40236.html 网上百度“odata 语法”会出来很多结果,其中有一项是比较一致的,那就是odata支持一下几种语 ...

  6. Asp.Net Web API 2

    Asp.Net Web API 2第十八课——Working with Entity Relations in OData   前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导 ...

  7. Mego(2) - NET主流ORM框架分析

    接上文我们测试了各个ORM框架的性能,大家可以很直观的看到各个ORM框架与原生的ADO.NET在境删改查的性能差异.这里和大家分享下我对ORM框架的理解及一些使用经验. ORM框架工作原理 典型ORM ...

  8. Dynamics CRM日期字段查询使用时分秒的方法

    本人微信公众号:微软动态CRM专家罗勇 ,回复293或者20190110可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 我们 ...

  9. Azure Application Insights REST API使用教程

    本文是Azure Application Insights REST API的简单介绍,并会包含一个通过Python消费API的示例/小工具. 新加入的team中的一项工作是制作日常的运维报表,制作方 ...

随机推荐

  1. iOS 辛格尔顿

    单例模式: 为什么使用单例,单例模式的用途是什么?以下我们举一个样例来诠释一下 举个大家都熟知的样例--Windows任务管理器,如图,我们能够做一个这种尝试,在Windows的"任务栏&q ...

  2. HDU 4864Task(更多的联合培训学校1)(贪婪)

    职务地址:pid=4864">HDU4864 这题又是一上来觉得是最小费用流,可是边太多.果然,敲完交上去后不断TLE.. 小优化了两次也没过. . . sad.. 后来看了题解才发现 ...

  3. MongoDB日常保养

    它引入了程序来进行维护管理工具 MongoDB的日常维护包含使用配置文件,设置訪问控制.Shell交互,系统监控和管理,数据库日常备份和恢复 启动和停止MongoDB 启动后能够通过数据库的IP加po ...

  4. Android异步载入全解析之IntentService

    Android异步载入全解析之IntentService 搞什么IntentService 前面我们说了那么多,异步处理都使用钦定的AsyncTask.再不济也使用的Thread,那么这个Intent ...

  5. 为大型数据文件每行只能产生id

    为大型数据文件每行只能产生id 4个主要思路: 1 单线程处理 2 普通多线程 3 hive 4 Hadoop 搜到一些參考资料 <Hadoop实战>的笔记-2.Hadoop输入与输出 h ...

  6. Repository、IUnitOfWork和IDbContext

    DDD 领域驱动设计-谈谈Repository.IUnitOfWork和IDbContext的实践 上一篇:<DDD 领域驱动设计-谈谈 Repository.IUnitOfWork 和 IDb ...

  7. TestNg它@Factory详细解释------如何更改参数值测试

    原创文章,版权所有所有.转载,归因:http://blog.csdn.net/wanghantong TestNg的@Factory注解从字面意思上来讲就是採用工厂的方法来创建測试数据并配合完毕測试 ...

  8. Android:创建耐磨应用 - 定义自己的布局

    创建自己的自定义布局(Creating Custom Layouts) 本文介绍如何创建自己的自定义通知和使用可穿戴UI库来创建自己的自定义布局同时你还需要知道耐磨设计标准(Wear Design P ...

  9. 左右v$datafile和v$tempfile中间file#

    v$datafile关于存储在文件中的数据视图的信息,v$tempfile查看存储在一个临时文件中的信息. 有两种观点file#现场,首先来看看官方文件的定义: V$DATAFILE This vie ...

  10. Sublime Text Package Collections

    JavaScriptNext - ES6 Syntax packagecontrol.io github.com Better JavaScript language definition for T ...