OData 1-5 OData語法(下)
接上篇 http://www.rzrgm.cn/PurpleTide/archive/2010/12/21/1912299.html ???
7) $expand 包含屬性和關系
假設??的??WagerInformation擁有一個屬性 UserInformation User 表示用戶信息, 另一個屬性 IEnumerable<CommonInformation> Commons 表示評論信息
使用 http://localhost:9527/ODataService.svc/WagerInformations?$expand=User ,Commons
返回的信息中就會包含相關類 (用于主外鍵關系)
- -# 如果不手動指定 而是自動關聯(lián)....那就悲劇了 可能數(shù)據(jù)庫中的所有表都有聯(lián)系...然后把整個數(shù)據(jù)庫返回.....
以前做過很囧的事情.就是開了級聯(lián)刪除...然后刪除了一個很基本的配置項.....整個數(shù)據(jù)庫基本空了
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 查詢數(shù)量
http://localhost:9527/ODataService.svc/WagerInformations/$count
返回的是真實數(shù)據(jù)不包含任何修飾 (raw data) 傳回的http body中就只有一個 "5" (不包含引號)
10) $orderby 排序
以下表達式按照BusinessUnitCode 降序 ,然后 EventName 升序排列
http://localhost:9527/ODataService.svc/WagerInformations?$orderby=BusinessUnitCode desc,EventName asc
11) $top
在10的基礎上 如果我只想返回第一條數(shù)據(jù) 那么如下
http://localhost:9527/ODataService.svc/WagerInformations?$orderby=BusinessUnitCode desc,EventName asc&$top=1
這里依然還是用& 來分隔不同的表達式
12) $skip
這東西一般和$top配合來分頁
以下表達式跳過第一條, 然后返回最多10條數(shù)據(jù)
http://localhost:9527/ODataService.svc/WagerInformations?$top=10&$skip=1
13) $inlinecount
在分頁取數(shù)據(jù)的時候,經(jīng)常要同時統(tǒng)計總記錄數(shù)
以下表達式在返回分頁數(shù)據(jù)的同時,順便同時返回所有的記錄數(shù)
http://localhost:9527/ODataService.svc/WagerInformations?$top=2&$skip=2&$inlinecount=allpages
如果表達式中有$filter 條件表達式 ,那么返回的就是符合條件的所有數(shù)據(jù)的數(shù)量
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
顯示元數(shù)據(jù)
http://localhost:9527/ODataService.svc/$metadata
浙公網(wǎng)安備 33010602011771號