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 @   2012  阅读(2899)  评论(3编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示