WCF Data Services查询

上一篇文章http://www.cnblogs.com/2018/archive/2010/10/15/1852579.html介绍了WCF Data Service的基础知识,下面介绍一下查询

查询在WCF Data Services十分的方便,更强的功能在这些类别中可以看到WCF Data Service的超级威力。可以直接在浏览器中输入查询表达式等进行访问

直接使用例子可从http://dskit.codeplex.com下载

查询表达式Query Expressions
一般的查询表达式【返回实体内容】

1. $filter

2. $inlinecount

3. $orderby

4. $skiptoken

5. $skip

6. $top

7. $select

8. $expand

不返回实体内容的查询表达式

· Service root path - returns information about the entity sets that can be accessed on the data service.

· Service operation - defines a method that is exposed as an endpoint on the data service. For more information, see Service Operations (WCF Data Services).

· $batch path segment - defines the URI that is used to submit requests that contain more than one operation.

· $count path segment - returns the number of entities in the set returned by the URI, without any additional response message metadata.

· $value path segment - returns the value of a property that is a primitive type, without any additional response message metadata. Also used to access binary data from a media resource.

· $metadata path segment - returns metadata, in conceptual schema definition language (CSDL), for the Entity Framework that describes the data model used by the data service.

语法和例子

http://host/<service>/[/<EntitySet>][(<EntityKey>)][/<NavigationProperty>[(<EntityKey>)/...]]] [?$expand] & [?$filter] & [?$orderby] & [?&top] & [?$skip]

http://localhost:1206/WcfDataService.svc/Customers?$orderby=City desc

 

http://localhost:1206/WcfDataService.svc/Customers?$orderby=City desc&$skip=10

http://localhost:1206/WcfDataService.svc/Customers?$skip=30&$top=10

 

http://localhost:1206/WcfDataService.svc/Customers('ALFKI')?$expand=Orders

http://localhost:1206/WcfDataService.svc/Customers('ALFKI')?$expand=Orders/Order_Details

 

http://localhost:1206/WcfDataService.svc/Customers?$filter=City eq 'london'

以上这些在上面的那个WEB服务启动后都可以直接使用,加上这些表达式就可以完成比较复杂的查询了。

查询表达式中的数据类型

clip_image002

Query Functions例子

http://www.northwindtraders.com/service.svc/Customers?$filter=isof('Ns.SpecialCustomer')

更多的函数和例子参考MSDN

Query Operators例子

· Grouping operators: ()

· Logical operators: and or not eq ne lt gt le ge

· Arithmetic operators: add sub mul div mod

http://localhost:1206/WcfDataService.svc/Orders?$filter=OrderDate gt datetime'1997-01-01'

更多的约定和例子参考MSDN

posted @ 2010-10-17 10:04  2012  阅读(2897)  评论(3编辑  收藏  举报