关于ADO.NET Entity Framework部分的内容见ADO.NET Entity Framework(1-4)

http://www.cnblogs.com/foundation/archive/2008/10/06/1304718.html

本文例子下载: http://files.cnblogs.com/wxwinter/lz.rar

目录

1    ADO.NET Data Service介绍    2

2    创建DataService项目    3

2.1    数据表    3

2.2    创建ASPNET项目    4

2.3    添架ADONET Entity模型    6

2.4    添加ADO.NET数据服务    10

2.5    在浏览器中查看    12

3    NET客启访问DataService    13

3.1    引用数据服务    13

3.2    查询    15

3.3    添加    15

3.4    修改    16

3.5    删除    16

3.6    异步查询    17

4    Silverlight客启访问DataService    18

4.1    引用服务    18

4.2    xaml页面    19

4.3    查询(WebClient方式)    20

4.4    查询    21

4.5    添加    22

4.6    编辑    22

4.7    删除    23

5    URL访问    24

5.1    运算符    24

5.2    关键字    24

5.3    函数    25

5.4    例1:直接访问Entity数据    26

5.5    例2:使用条件    28

5.6    例3:排序    29

5.7    例4:分页    31

5.8    例5:函数的使用    32

6    WEB方法    33

6.1    服务    33

6.2    访问    34

7    拦截器    35

7.1    查询拦截    35

7.2    修改拦截器    36

ADO.NET Data Service介绍

1.ADO.NET Data Service的DataServiceHost是一个WCF Service,由System.Data.Services.DataService<T>提供来自NET3.5 SP1 类库中的System.Data.Services.dll

2.DataServices会自动为加载的Entity对象生成具有增查删改功能的WCF服务

3.DataServices是以Http方式与客户端进行通信.任何可以实现HTTP访问的客户端,都可以与DataServices交互

4. NET3.5 SP1的客户端可以使用System.Data.Services.Client.DataServiceContext与DataServices交互,该类来自NET3.5 SP1 类库中的System.Data.Services.Client.dll 文件

5. Silverlight 2.0客户端可以使用System.Data.Services.Client.DataServiceContext与DataServices交互,该类来自Silverlight 2.0 类库中的System.Data.Services.Client 文件

6.DataServices提供ATOM与JSON两种格式用来描述数据结构,说明如下:

ATOM

与RSS类似,也是建立在XML数据格式的基础之上的

Atom相对RSS格式而言,进行了扩展,提供了比RSS更多的项目属性

JSON

格式如下

{

"name": "wxd",

"time": "2008/10/10 10:10",

"value": 123.456,

"list": [ "wxwinter", "lzm"]

}

创建DataService项目

数据表

tabA

tabX

创建ASPNET项目

添架ADONET Entity模型

添加ADO.NET数据服务

public class myWebDataService : DataService<myDBEntities>

{

public static void InitializeService(IDataServiceConfiguration config)

{

config.SetEntitySetAccessRule("*", EntitySetRights.All);

// * :表示全部实体集

// EntitySetRights.All : 表示全部的操作权限

}

}

在浏览器中查看

NET客启访问DataService

引用数据服务

查询

//查询

private void button1_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

myService.myDBEntities server = new WinFormClient.myService.myDBEntities(url);

foreach (var v in server.tabA)

{

Console.WriteLine("{0},{1},{2}", v.a, v.b, v.c);

}

//-

foreach (var v in server.tabX.Where(p=>p.x=="002"))

{

Console.WriteLine("{0},{1},{2}", v.x, v.y, v.z);

}

}

lzm ,2 ,5

wxd ,1 ,4

wxwinter ,3 ,6

002 ,8 ,llzzmm

添加

//添加

private void button2_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

myService.myDBEntities server = new WinFormClient.myService.myDBEntities(url);

server.AddTotabA(new myService.tabA() { a = "wxdlzm", b = "333", c = "xxx" });

server.SaveChanges();

}

修改

//修改

private void button3_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

myService.myDBEntities server = new WinFormClient.myService.myDBEntities(url);

var v = server.tabA.Where(p => p.a == "wxdlzm").First();

v.b = "hello";

server.UpdateObject(v);

server.SaveChanges();

}

删除

//删除

private void button4_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

myService.myDBEntities server = new WinFormClient.myService.myDBEntities(url);

var v = server.tabA.Where(p => p.a == "wxdlzm").First();

server.DeleteObject(v);

server.SaveChanges();

}

异步查询

//异步查询

myService.myDBEntities server1;

//开始查询

private void button5_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

Uri urlE = new Uri("http://localhost:1468/myWebDataService.svc/tabX");

server1 = new WinFormClient.myService.myDBEntities(url);

server1.BeginExecute<myService.tabX>(urlE, new AsyncCallback(executed), null);

}

//返回结果

void executed(IAsyncResult obj)

{

var tp = server1.EndExecute<myService.tabX>(obj);

foreach (var v in tp)

{

Console.WriteLine("{0},{1},{2}", v.x, v.y, v.z);

}

}

Silverlight客启访问DataService

Silverlight 2.0 可以利用两种方法与DataServices交互:

  • HttpWebRequest 与 HttpWebResponse
  • System.Data.Services.Client.DataServiceContext

Silverlight 2.0 是使用异步方法来连接远程数据源。

LINQ 的 select ,要用 BeginExecute() 和 EndExecute()

LINQ 的 SaveChanges(),要用 BeginSaveChanges() 和 EndSaveChanges()

引用服务

xaml页面

<StackPanel Loaded="StackPanel_Loaded">

<data:DataGrid Name="dg"></data:DataGrid>

<Button Content="DataServiceContext方式加载数据" Width="200" Click="loadData_Click" />

<Button Content="WebClient方式加载数据" Width="200" Click="loadData2_Click" />

<Button Content="添加" Width="200" Click="add_Click" />

<Button Content="修改" Width="200" Click="edit_Click" />

<Button Content="删除" Width="200" Click="del_Click" />

</StackPanel>

myService.myDBEntities server;

private void StackPanel_Loaded(object sender, RoutedEventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

server = new myService.myDBEntities(url);

}

void saveChanges_completed(IAsyncResult obj)

{

}

查询(WebClient方式)

//WebClient方式加载数据

private void loadData2_Click(object sender, RoutedEventArgs e)

{

Uri uri = new Uri("http://localhost:1468/myWebDataService.svc/tabA");

WebClient client = new WebClient();

client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_completed);

client.OpenReadAsync(uri);

}

void client_completed(object sender, OpenReadCompletedEventArgs e)

{

if (e.Error == null)

{

XmlReader reader = XmlReader.Create(e.Result);

XDocument ls = XDocument.Load(reader);

XNamespace xmlns = "http://www.w3.org/2005/Atom";

XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";

XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";

var list = from x in ls.Descendants(xmlns + "entry")

select new myService.tabA

{

a= x.Descendants(d + "a").First().Value, b = x.Descendants(d + "b").First().Value, c = x.Descendants(d + "c").First().Value

};

dg.ItemsSource = list;

}

}

查询

//加载

private void loadData_Click(object sender, RoutedEventArgs e)

{

Uri urlE = new Uri("http://localhost:1468/myWebDataService.svc/tabX");

server.BeginExecute<myService.tabX>(urlE, new AsyncCallback(load_completed), null);

}

void load_completed(IAsyncResult obj)

{

var tp = server.EndExecute<myService.tabX>(obj);

this.dg.ItemsSource = tp.ToList();

}

添加

//添加

private void add_Click(object sender, RoutedEventArgs e)

{

server.AddTotabX(new myService.tabX() { x="007",z="sss",y="sss" });

server.BeginSaveChanges(new AsyncCallback(saveChanges_completed), null);

}

编辑

//编辑

private void edit_Click(object sender, RoutedEventArgs e)

{

Uri urlE = new Uri("http://localhost:1468/myWebDataService.svc/tabX");

server.BeginExecute<myService.tabX>(urlE, new AsyncCallback(begin_edit), null);

}

void begin_edit(IAsyncResult obj)

{

var tp = server.EndExecute<myService.tabX>(obj).Where(p => p.x == "007 ").First();

tp.y = "hello";

server.UpdateObject(tp);

server.BeginSaveChanges(new AsyncCallback(saveChanges_completed), null);

}

删除

//删除

private void del_Click(object sender, RoutedEventArgs e)

{

Uri urlE = new Uri("http://localhost:1468/myWebDataService.svc/tabX");

server.BeginExecute<myService.tabX>(urlE, new AsyncCallback(begin_del), null);

}

void begin_del(IAsyncResult obj)

{

var tp = server.EndExecute<myService.tabX>(obj).Where(p => p.x == "007 ").First();

server.DeleteObject(tp);

server.BeginSaveChanges(new AsyncCallback(saveChanges_completed), null);

}

URL访问

DataService 支持URL方式访问

格式

http://[Url]/[ServiceName]/[EntityName]/[NavigationOptions]?[QueryOptions]

Url: 数据服务所在的网址

ServiceName: 数据服务的名称

EntityName: Entity 名称或是 Service 方法名称

NavigationOptions: 查询 Entity 中关联的设定

QueryOptions: 查询的选项

运算符

运算符

说明

and

 

or

 

not

 

eq

=

ne

!=

lt

<

gt

>

le

<=

ge

>=

add

+

sub

-

mul

*

div

/

mod

余数

()

 

关键字

expand

类似于LINQ中的LoadOptions,以此来指定加载此对象相关的通过expand指定的对象。如果需要加载多个对象,用逗号分隔。

orderby

指定排序方式。语法为:$orderby=Field [ASC|DESC], [Field[ASC|DESC]]

Skip

Top

类似于LINQ中的Skip(PageSize * PageIndex).Take(PageSize)用来实现分页。

Filter

通过filter这个参数可以在URL里传递过滤条件。

函数

bool substringof(string p0, string p1)

 

bool startswith(string p0, string p1)

 

int indexof(string arg)

 

string remove(string p0, int pos)

 

string remove(string p0, string find, string replace)

 

string substring(string p0, int pos, int length)

 

string toupper(string p0)

 

string concat(string p0, string p1)

 

bool endswith(string p0, string p1)

 

int length(string p0)

 

string insert(string p0,int pos, string p1)

 

string remove(string p0, int pos, int length)

 

string substring(string p0, int pos)

 

string tolower(string p0)

 

string trim(string p0)

 

int day(DateTime)

 

int month(DateTime)

 

int hour(DateTime)

 

int second(DateTime)

 

int minute(DateTime)

 

int year(DateTime)

 

double round(double)

 

decimal floor(decimal)

 

decimal round(decimal)

 

double ceiling(double)

 

double floor(double)

 

decimal ceiling(decimal)

 

例1:直接访问Entity数据

http://localhost:1468/myWebDataService.svc/tabA

由于返回的数据是ATOM格式的,如果浏览器支持该格式,会用阅读方式打开,如IE7用RSS阅读器方式打开

以下是返回的数据

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<feed xml:base="http://localhost:1468/myWebDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">

<title type="text">tabA</title>

<id>http://localhost:1468/myWebDataService.svc/tabA</id>

<updated>2008-11-17T11:14:32Z</updated>

<link rel="self" title="tabA" href="tabA" />

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('lzm%20%20%20%20%20%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T11:14:32Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('lzm%20%20%20%20%20%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">lzm </d:a>

<d:b xml:space="preserve">2 </d:b>

<d:c xml:space="preserve">5 </d:c>

</m:properties>

</content>

</entry>

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('wxd%20%20%20%20%20%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T11:14:32Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('wxd%20%20%20%20%20%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">wxd </d:a>

<d:b xml:space="preserve">1 </d:b>

<d:c xml:space="preserve">4 </d:c>

</m:properties>

</content>

</entry>

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('wxdlzm%20%20%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T11:14:32Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('wxdlzm%20%20%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">wxdlzm </d:a>

<d:b xml:space="preserve">333 </d:b>

<d:c xml:space="preserve">xxx </d:c>

</m:properties>

</content>

</entry>

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('wxwinter%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T11:14:32Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('wxwinter%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">wxwinter </d:a>

<d:b xml:space="preserve">3 </d:b>

<d:c xml:space="preserve">6 </d:c>

</m:properties>

</content>

</entry>

</feed>

例2:使用条件

http://localhost:1468/myWebDataService.svc/tabA?$filter=a eq 'wxd'

http://localhost:1468/myWebDataService.svc/tabA?$filter=(a eq 'wxwinter') and (b eq '3')

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<feed xml:base="http://localhost:1468/myWebDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">

<title type="text">tabA</title>

<id>http://localhost:1468/myWebDataService.svc/tabA</id>

<updated>2008-11-17T11:26:29Z</updated>

<link rel="self" title="tabA" href="tabA" />

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('wxd%20%20%20%20%20%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T11:26:29Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('wxd%20%20%20%20%20%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">wxd </d:a>

<d:b xml:space="preserve">1 </d:b>

<d:c xml:space="preserve">4 </d:c>

</m:properties>

</content>

</entry>

</feed>

例3:排序

http://localhost:1468/myWebDataService.svc/tabA?$filter=a ne 'wxd' &$orderby=b

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<feed xml:base="http://localhost:1468/myWebDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">

<title type="text">tabA</title>

<id>http://localhost:1468/myWebDataService.svc/tabA</id>

<updated>2008-11-17T11:28:10Z</updated>

<link rel="self" title="tabA" href="tabA" />

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('lzm%20%20%20%20%20%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T11:28:10Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('lzm%20%20%20%20%20%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">lzm </d:a>

<d:b xml:space="preserve">2 </d:b>

<d:c xml:space="preserve">5 </d:c>

</m:properties>

</content>

</entry>

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('wxwinter%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T11:28:10Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('wxwinter%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">wxwinter </d:a>

<d:b xml:space="preserve">3 </d:b>

<d:c xml:space="preserve">6 </d:c>

</m:properties>

</content>

</entry>

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('wxdlzm%20%20%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T11:28:10Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('wxdlzm%20%20%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">wxdlzm </d:a>

<d:b xml:space="preserve">333 </d:b>

<d:c xml:space="preserve">xxx </d:c>

</m:properties>

</content>

</entry>

</feed>

例4:分页

http://localhost:1468/myWebDataService.svc/tabA?$filter=a ne 'wxd' &$orderby=b &$skip=2&top=2

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<feed xml:base="http://localhost:1468/myWebDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">

<title type="text">tabA</title>

<id>http://localhost:1468/myWebDataService.svc/tabA</id>

<updated>2008-11-17T11:30:20Z</updated>

<link rel="self" title="tabA" href="tabA" />

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('wxdlzm%20%20%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T11:30:20Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('wxdlzm%20%20%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">wxdlzm </d:a>

<d:b xml:space="preserve">333 </d:b>

<d:c xml:space="preserve">xxx </d:c>

</m:properties>

</content>

</entry>

</feed>

例5:函数的使用

http://localhost:1468/myWebDataService.svc/tabA?$filter=a eq trim(' wxd ')

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<feed xml:base="http://localhost:1468/myWebDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">

<title type="text">tabA</title>

<id>http://localhost:1468/myWebDataService.svc/tabA</id>

<updated>2008-11-17T12:01:49Z</updated>

<link rel="self" title="tabA" href="tabA" />

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('wxd%20%20%20%20%20%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T12:01:49Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('wxd%20%20%20%20%20%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">wxd </d:a>

<d:b xml:space="preserve">1 </d:b>

<d:c xml:space="preserve">4 </d:c>

</m:properties>

</content>

</entry>

</feed>

WEB方法

[WebGet] 使用 GET方式访问

[WebInvoke] 使用 POST/PUT/DELETE 方式访问

服务

public class myWebDataService : DataService<myDBEntities>

{

public static void InitializeService(IDataServiceConfiguration config)

{

config.SetEntitySetAccessRule("*", EntitySetRights.All);

// * :表示全部实体集

// EntitySetRights.All : 表示全部的操作权限

// config.SetServiceOperationAccessRule("getTabA", ServiceOperationRights.All);

config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);

// * :表示全部实体集

// ServiceOperationRights.All : 表示全部的操作权限

}

[WebGet]

public IQueryable<tabA> getTabA(string a)

{

var v= CurrentDataSource.tabA.Where(p => p.a == a);

return v;

}

[WebInvoke]

public IQueryable<tabX> getTabX(string x)

{

var v = CurrentDataSource.tabX.Where(p => p.x == x);

return v;

}

}

访问

方法名?参数='值

'

http://localhost:1468/myWebDataService.svc/getTabA?a='lzm'

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<feed xml:base="http://localhost:1468/myWebDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">

<title type="text">getTabA</title>

<id>http://localhost:1468/myWebDataService.svc/getTabA</id>

<updated>2008-11-17T02:23:29Z</updated>

<link rel="self" title="getTabA" href="getTabA" />

<entry>

<id>http://localhost:1468/myWebDataService.svc/tabA('lzm%20%20%20%20%20%20%20')</id>

<title type="text"></title>

<updated>2008-11-17T02:23:29Z</updated>

<author>

<name />

</author>

<link rel="edit" title="tabA" href="tabA('lzm%20%20%20%20%20%20%20')" />

<category term="myDBModel.tabA" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<content type="application/xml">

<m:properties>

<d:a xml:space="preserve">lzm </d:a>

<d:b xml:space="preserve">2 </d:b>

<d:c xml:space="preserve">5 </d:c>

</m:properties>

</content>

</entry>

</feed>

拦截器

查询拦截:当你仅仅想把具有某种状态或者特征的数据返回给客户端时,用拦截查询就可以实现

修改拦截:可以拦截提交到服务器的的数据更新操作:Add, Change ,Delete

查询拦截

public class myWebDataService : DataService<myDBEntities>

{

public static void InitializeService(IDataServiceConfiguration config)

{

config.SetEntitySetAccessRule("*", EntitySetRights.All);

// * :表示全部实体集

// EntitySetRights.All : 表示全部的操作权限

}

[QueryInterceptor("tabX")]

public System.Linq.Expressions.Expression<Func<tabX, bool>> query_tabX()

{

return p => p.z != "wwxxdd"; //为真表示允许查询

}

}

不使用QueryInterceptor的结果

使用QueryInterceptor的结果

修改拦截器

public class myWebDataService : DataService<myDBEntities>

{

public static void InitializeService(IDataServiceConfiguration config)

{

config.SetEntitySetAccessRule("*", EntitySetRights.All);

// * :表示全部实体集

// EntitySetRights.All : 表示全部的操作权限

}

[ChangeInterceptor("tabX")]

public void change_tabX(tabX en, UpdateOperations operation)

{

//-

if (operation == UpdateOperations.Add)

{

if (string.IsNullOrEmpty(en.y))

{

//如果[y]为空的处理代码

}

}

//-

if (operation == UpdateOperations.Change)

{ }

//-

if (operation == UpdateOperations.Delete)

{ }

}

}

ADO.NET Data Service的更多相关文章

  1. Using ADO.NET Data Service

    ADO.NET Data Service是随同Visual Studio 2008 SP1提供的用于构建在数据对象模型 (如EF-DEMX, LINQ-DBML) 之时来快速提供企业网内外的轻量级数据 ...

  2. WCF Data Service 使用小结 (一)—— 了解OData协议

    最近做了一个小项目,其中用到了 WCF Data Service,之前是叫 ADO.NET Data Service 的.关于WCF Data Service,博客园里的介绍并不多,但它确实是个很好的 ...

  3. WCF Data Service 使用小结 —— 了解OData(一)

    最近做了一个小项目,其中用到了 WCF Data Service,之前是叫 ADO.NET Data Service 的.关于WCF Data Service,博客园里的介绍并不多,但它确实是个很好的 ...

  4. 一步一步学Silverlight 2系列(17):数据与通信之ADO.NET Data Services

    概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...

  5. 我的WCF Data Service 系列 (一、为什么要有WCF Data Service)

    开篇先说两名题外话, 在博问上,经常看到有个问性能问题,比如Entity Framework的性能行不行啊之类的. 其实这个行不行,关键还是看对象,一夜家族的老七可能勉强吃点蓝片片,也就行了,可真要让 ...

  6. 自定义Data Service Providers

    自定义Data Service Providers 作者:AlexJ 翻译:谈少民 原文链接:http://blogs.msdn.com/b/alexj/archive/2010/01/07/data ...

  7. WCF Data Service

    WCF Data Service:http://www.cnblogs.com/shanyou/category/240225.html

  8. WCF Data Service 使用小结(二) —— 使用WCF Data Service 创建OData服务

    在 上一章 中,介绍了如何通过 OData 协议来访问 OData 服务提供的资源.下面来介绍如何创建一个 OData 服务.在这篇文章中,主要说明在.NET的环境下,如何使用 WCF Data Se ...

  9. 调用WCF Data Service的几点Tips

    使用Linq实现sql in statement的时候,用EF的时候可以通过Contains.Exists的方法实现.但是在使用WCF Data Service的context的时候,会报不支持该方法 ...

随机推荐

  1. Python Challenge 第十一关

    第十一关,一张模糊的图,题目为 odd even,源代码中也没任何提示,看来又是图像处理. 这张模糊的图看起来没什么头绪,但是题目给了个奇数和偶数,就先试试坐标吧,根据原图来生成一个新图.我第一次尝试 ...

  2. HDU - 2970 Suffix reconstruction

    Discription Given a text s[1..n] of length n, we create its suffix array by taking all its suffixes: ...

  3. Codeforces 869 C The Intriguing Obsession

    题目描述 — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, ...

  4. 键盘弹出后上提view隐藏后下拉view还原并修改scroll过程中旋转屏幕到竖屏view显示错误

    1,注册键盘相应事件 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillSho ...

  5. source(.)/export/shell

    用户登录到Linux系统后,系统将启动一个用户shell.在这个shell中,可以使用shell命令或声明变量,也可以创建并运行shell脚本程序.运行shell脚本程序时,系统将创建一个子shell ...

  6. GCC编译笔记

    需要移植一个vs2008的项目到linux上,代码比较复杂,重新写比较困难,于是开始折腾 首先移植到codeblocks上,sprints_s这类的vs函数都要改,windows调用要改 编译通过 c ...

  7. VIM正则表达式查找替换

      0. 一些需要注意的不同 VIM中的正则表达式和其他的有点不一样 (1) 有些符号要用\转义,比如\+表示重复一次或以上,其他的还有一些,:h pattern查看(2) 非贪婪匹配用\{-}, 如 ...

  8. Android中Java与web通信

    Android中Java与web通信不是新的技术了,在android公布之初就支持这样的方式,2011年開始流行,而这样的模式开发也称作Hybird模式. 这里对android中的Java与web通信 ...

  9. 【Python】学习笔记十五:循环对象

    循环对象 所谓的循环对象,包含有一个next()方法(python3中为__next__() ),这个方法的目的就是进行到下一个结果,而在结束一系列结果之后,举出StopIteration错误 当一个 ...

  10. ExtJs4学习(一):正确认识ExtJs4

    认识ExtJs 1.Javat能用ExtJs吗? 它是展现层的技术,与JS,HTML,CSS有关.至于server端是.Net,还是PHP等无关. 2.ExtJs适合什么样的项目? 依照官方的说法,E ...