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'
查詢時間:
組合查詢表達式: 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 |
()
|

浙公網安備 33010602011771號