WCF Data Services查询

简介: 上一篇文章http://www.cnblogs.com/2018/archive/2010/10/15/1852579.html介绍了WCF Data Service的基础知识,下面介绍一下查询 查询在WCF Data Services十分的方便,更强的功能在这些类别中可以看到WCF Data Service的超级威力。

上一篇文章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

相关文章
|
数据库 测试技术 安全
使用Entity Framework和WCF Ria Services开发SilverLight之2:POCO
在上一篇中《使用Entity Framework和WCF Ria Services开发SilverLight之1:简单模型》我们提出这类简单模型的几个问题: 1:实体模型被紧耦合在EDM中,同时它不能项目(模块)使用。
1299 0
|
前端开发
WCF更新服务引用报错的原因之一
WCF更新服务引用报错的原因之一
|
C# 数据安全/隐私保护
c#如何创建WCF服务到发布(SqlServer版已经验证)
c#如何创建WCF服务到发布(SqlServer版已经验证)
129 0
|
安全 数据库连接 数据库
WCF服务创建到发布(SqlServer版)
在本示例开始之前,让我们先来了解一下什么是wcf? wcf有哪些特点? wcf是一个面向服务编程的综合分层架构。该架构的项层为服务模型层。 使用户用最少的时间和精力建立自己的软件产品和外界通信的模型。它使得开发者能够建立一个跨平台的安全、可信赖、事务性的解决方案。且能与已有系统兼容写作。 简单概括就是:一组数据通信的应用程序开发接口。
249 0