OData语法
来源:互联网 发布:最新域名 编辑:程序博客网 时间:2024/06/14 21:39
假设目前提供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'
查询时间:
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
()
原文地址:http://blogs.msdn.com/b/alexj/archive/2009/11/18/tip-44-how-to-navigate-an-odata-compliant-service.aspx
7) $expand 包含属性和关系
假设的WagerInformation拥有一个属性 UserInformation User 表示用户信息, 另一个属性 IEnumerable<CommonInformation> Commons 表示评论信息
使用 http://localhost:9527/ODataService.svc/WagerInformations?$expand=User ,Commons
返回的信息中就会包含相关类 (用于主外键关系)
- -# 如果不手动指定 而是自动关联....那就悲剧了 可能数据库中的所有表都有联系...然后把整个数据库返回.....
以前做过很囧的事情.就是开了级联删除...然后删除了一个很基本的配置项.....整个数据库基本空了
8) $select 查询字段的列表(和sql中select后面的表达式一样)
以下url只想返回查询所有信息的EventName属性
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
- OData语法
- OData语法
- OData 语法使用规则介绍
- OData
- Introducing OData
- OData demo
- 什么是OData?
- odata接口参考网站
- EXTJS Odata 可能解决方案
- 关于后端使用 OData
- nodejs模块 node-odata
- sapui5 访问OData数据
- Odata数据导入Excel
- OData Version 4.0 URL
- ODATA 系列文章
- Odata数据展示
- odata初探01
- SAP ui5 table odata
- Android编译环境——ubuntu12.04上android2.3.4编译错误以及解决
- CopyU! 增加新的缓存机制,提升运行性能
- Linux下Apache与Tomcat的完全分布式集群配置(负载均衡
- 【JXTA中双向可靠的信息渠道】
- UML中几种类间关系:继承、实现、依赖、关联、聚合、组合的联系与区别
- OData语法
- 仿QQ空间登录,解决键盘挡住输入框的问题
- 从南极之争谈软件架构十个技巧,及成功团队具备的气质
- 用JavaScript(js)对时间格式化
- 推荐几个android 学习与应用 网站
- php绝对路径与相对路径之间关系的的深入研究
- 苹果全线新品发布时间表
- jQuery获取form中radio的Value值
- android button light 流程分析(二) — HAL & JNI