关于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学习杂记_8_从程序外部传参的办法sys.argv

    Python用 sys.argv[] 实现从程序外部传参 “外部”的含义,其实就是这些参数不是你在程序中定义的,而是在程序之外通过输入操作传递进来的.sys.argv 会返回一个元组,元组的首个元素即 ...

  2. hdu 1576(逆元)

    A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. 牛客网 牛客练习赛13 A.幸运数字Ⅰ

    A.幸运数字Ⅰ 链接:https://www.nowcoder.com/acm/contest/70/A来源:牛客网     水题.   代码: #include<iostream> #i ...

  4. 稀疏编码(Sparse Coding)的前世今生(一) 转自http://blog.csdn.net/marvin521/article/details/8980853

    稀疏编码来源于神经科学,计算机科学和机器学习领域一般一开始就从稀疏编码算法讲起,上来就是找基向量(超完备基),但是我觉得其源头也比较有意思,知道根基的情况下,拓展其应用也比较有底气.哲学.神经科学.计 ...

  5. Light oj 1044 - Palindrome Partitioning(区间dp)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 dp[i][j]表示i到j直接的最小回文区间个数,直接看代码 #include ...

  6. 解决百度ueditor配置上传目录为外部目录时,项目启动访问不到图片的问题。

    如图所示,公司项目用到了百度的ueditor,配置的上传目录并不在项目根目录下,而是在外部目录中.于是在上传图片时,出现了无法获取图片的问题. 解决方法:添加该目录至tomcat项目部署目录中,如下图 ...

  7. shell 实现自动备份nginx下的站点

    shell 实现自动备份nginx下的站点 优点 实现自动备份ngnix下的所有运行的站点 自定义排除备份站点,支持三种排除 自动维护备份目录,防止备份目录无限扩大 备份压缩tar.gz格式 源码: ...

  8. C#规范整理·泛型委托事件

    基于泛型,我们得以将类型参数化,以便更大范围地进行代码复用.同时,它减少了泛型类及泛型方法中的转型,确保了类型安全.委托本身是一种引用类型,它保存的也是托管堆中对象的引用,只不过这个引用比较特殊,它是 ...

  9. VS中Debug模式和Release模式的区别

    一.Debug 和 Release 编译方式的本质区别 Debug 通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序.Release 称为发布版本,它往往是进行了各种优化,使得程 ...

  10. Android 使用SharedPreferences数据存储

    自己写了个SP辅助类 尽管写的有点啰嗦,也是自己的成果.例如以下: package com.yqy.yqy_testsputil; import android.annotation.Suppress ...