关于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. Mysql同台机器主从配置

    Mysql主从配置 安装主Mysql 安装前的准备 检查系统是否存在mysql用户 [root@test mysql]# less /etc/passwd | grep mysql mysql:x:5 ...

  2. 学习总结——JMeter做http接口压力测试

    JMeter做http接口压力测试 测前准备 用JMeter做接口的压测非常方便,在压测之前我们需要考虑这几个方面: 场景设定 场景分单场景和混合场景.针对一个接口做压力测试就是单场景,针对一个流程做 ...

  3. 一个关于集合的问题,为什么添加进List集合中的元素被莫名其妙的改变了

    以前自己理解的不够深刻,特此记录一下提醒自己,如果正好也帮到了你,我会很开心.相信只有自己正好遇到这个问题,才觉得哦,原来这样.自己小白,大神莫喷 为什么添加进List集合中的元素被莫名其妙的改变了? ...

  4. ConstraintLayout 约束布局

    约束布局ConstraintLayout 这种布局方式出现已经有一段时间了,刚出现的时候一直以为这种布局只是针对拖拽使用的布局,最近在新项目里看到了这种布局,又重新学习了这种布局,才发现以前真的是图样 ...

  5. scala之split()函数用法

    split()函数: def split(arg0: String): Array[String] def split(arg0: String, arg1: Int): Array[String] ...

  6. 8 Most Required Examples Reference For Oracle Forms

    Check the following 8 Links for best Oracle Forms examples with source code (Fmb files), which will ...

  7. 最长递增子序列问题—LIS

    问题:给定一组数 a0,a0,....,an-1. 求该序列的最长递增(递减)序列的长度. 最长递增子序列长度的求法有O(n^2)和O(nlogn)两种算法. 1.复杂度为O(n^2)的算法. 设L[ ...

  8. 经验分享 | Burpsuite抓取非HTTP流量

    使用Burp对安卓应用进行渗透测试的过程中,有时候会遇到某些流量无法拦截的情况,这些流量可能不是HTTP协议的,或者是“比较特殊”的HTTP协议(以下统称非HTTP流量).遇到这种情况,大多数人会选择 ...

  9. 报错: Access restriction: The type JPEGImageEncoder is not accessible due to restriction on required library

    报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...

  10. 360Webscan Bypass

    来到select正则: ? 1 \<.+javascript:window\[.{1}\\x|<.*=(&#\d+?;?)+?>|<.*(data|src)=data: ...