Custom Data Service Providers
Custom Data Service Providers
Introduction
Data Services sits above a Data Service Provider, which is responsible for interacting with the underlying Data Source on behalf of the Data Service.
Data Services ships with some internal providers, and makes it possible for you to create custom providers too.
So the obvious question is...
Do you need a Custom Data Provider?
Creating a Custom Data Service Provider is a fair amount of work, which of course provides big dividends like, allowing people to:
- Query and manipulate your data via the Data Services Client in:
- WPF
- WinForms
- SilverLight
- etc
- Query you data directly via a browser
- Query and manipulate your data via Javascript and associated frameworks like JQuery
- Query your data via knowledge worker tools like PowerPivot.
- etc.etc.etc.
But before you jump into creating a custom provider, see if you fall into one of the following camps, all of which have a much easier solution:
Entity Framework
If you plan on putting a Data Service over the Entity Framework the answer is no you don't need to write a custom provider.
Data Services has an implementation that talks to the Entity Framework in the box.
You simply point your DataService at your strongly typed ObjectContext, and that’s it:
public class NorthwindDataService:
DataService<NorthwindEntities>
In this example NorthwindEntities is your strongly typed ObjectContext representing the Northwind database.
For a good example of an OData Service built using the Entity Framework check out this post.
LINQ to SQL
If you want to create a Data Service over a LINQ to SQL data source you should take a look at this project on Code Gallery.
It includes sample code you can use to extend your strongly typed DataContext class to implement theIUpdatable interface.
This in conjunction with the Reflection Provider means you can use your LINQ to SQL DataContext just like an Entity Framework ObjectContext:
public class NorthwindDataService:
DataService<NorthwindDataContext>
Reflection Provider
If you have your own class that can represent your Data Source, and it has a number of strongly typed IQueryable properties like this:
public class MyDataSource
{
public IQueryable<Product> Products { get {…} }
public IQueryable<Categories> Categories { get {…} }
}
The built-in reflection provider can turn this into a read-only service and infer ResourceSets, Types and Properties automatically.
You can even make this read-write by extending your class to implement IUpdatable:
public class MyDataSource: IUpdatable
In fact this is exactly how the LINQ to SQL example above works.
For a good example of an OData Service created using the reflection provider check out Tip 56.
So when do you actually need a custom provider?
The reflection provider is very useful for some scenarios.
But is has a number of limitations that might disqualify it for your scenario:
- It is static, i.e. the shape of the service can’t evolve over time.
- It needs CLR classes for each ResourceType, which you might not have.
- It needs to find Id or {Type}Id properties to use as keys.
- It blindly exposes all public properties of the CLR classes.
- It gives you less control over streaming or paging.
- You can’t take advantage of advanced features like Open Types, which allows resources to optionally include more Open Properties.
- You have less control, for example you can't log requests as easily or modify metadata or rename properties
- etc. etc. etc.
If any of these are important it’s time to create a Custom Data Service Provider…
Creating a Data Service Provider Series
This series of posts will grow to cover all of the major DSP interfaces and show case lots of scenarios
Part 1 – Intro
Part 2 – IServiceProvider and DataSources
Part 3 – IDataServiceMetadataProvider
Part 4 – Minimal Running Service
Part 5 – Query
Part 6 – Query Interactions
Part 7 – UpdatesPart 8 - Relationships
Part 9 - Untyped
possible future installments…
Part 10 – ETags
Part 11 – Friendly Feeds
Part 12 – Streaming
Part 13 – Advanced Paging
Custom Data Service Providers的更多相关文章
- 自定义Data Service Providers
自定义Data Service Providers 作者:AlexJ 翻译:谈少民 原文链接:http://blogs.msdn.com/b/alexj/archive/2010/01/07/data ...
- POJ 3911:Internet Service Providers
Internet Service Providers Time Limit: 2MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I ...
- WCF Data Service
WCF Data Service:http://www.cnblogs.com/shanyou/category/240225.html
- 我的WCF Data Service 系列 (一、为什么要有WCF Data Service)
开篇先说两名题外话, 在博问上,经常看到有个问性能问题,比如Entity Framework的性能行不行啊之类的. 其实这个行不行,关键还是看对象,一夜家族的老七可能勉强吃点蓝片片,也就行了,可真要让 ...
- Laravel 之Service Providers
Service providers are the central place of all Laravel application bootstrapping. Your own applicati ...
- WCF Data Service 使用小结(二) —— 使用WCF Data Service 创建OData服务
在 上一章 中,介绍了如何通过 OData 协议来访问 OData 服务提供的资源.下面来介绍如何创建一个 OData 服务.在这篇文章中,主要说明在.NET的环境下,如何使用 WCF Data Se ...
- WCF Data Service 使用小结 (一)—— 了解OData协议
最近做了一个小项目,其中用到了 WCF Data Service,之前是叫 ADO.NET Data Service 的.关于WCF Data Service,博客园里的介绍并不多,但它确实是个很好的 ...
- WCF Data Service 使用小结 —— 了解OData(一)
最近做了一个小项目,其中用到了 WCF Data Service,之前是叫 ADO.NET Data Service 的.关于WCF Data Service,博客园里的介绍并不多,但它确实是个很好的 ...
- 调用WCF Data Service的几点Tips
使用Linq实现sql in statement的时候,用EF的时候可以通过Contains.Exists的方法实现.但是在使用WCF Data Service的context的时候,会报不支持该方法 ...
随机推荐
- 802.11(wifi)的MAC层功能
MAC层是802.11的主要功能部分.上层应用通过调用MAC层提供的接口原语调用MAC层的功能. MAC一共向上提供了2大类接口原语,共30种.数据(1)和管理(29).数据部分就是提供普通数据包的收 ...
- oralce 获取自定义主键编码,有并发问题
F_GET_SEQUENCE,功能函数,当多个服务同时调用此函数,可能产生并发问题,待解决,加主键. CREATE OR REPLACE Function f_Get_Sequence(As_Comp ...
- sql二进制数据权限
(3为权限组合值,结果为1=列表 2=新建 4=修改 8=删除) select 3 & 1 select 3 & 2 select 3 & 4 select 3 & 2 ...
- Android多点触控(图片的缩放Demo)
本文主要介绍Android的多点触控,使用了一个图片缩放的实例,来更好的说明其原理.须要实现OnTouchListener接口,重写当中的onTouch方法. 实现效果图: 源码: 布局文 ...
- ProgressBar样式总结与自己主动填充方法(代码)
有时候开发的时候须要用一个进度条告知用户眼下正在执行一个耗时操作,可是并不须要明白知道某个value来setProgress,所以就能够自己定义一个时间和进度让进度条自己主动执行了. 以下是代码: H ...
- HTML5实际和离线应用分析
当前离线Web申请书,即,该装置不能访问因特网时的应用的执行.HTML5离线应用重点,主要开发人员希望.步骤离线应用开发有:首先我们应该知道设备是否可以连接;然后,它也应该可以访问某些资源(像.CSS ...
- 编译命令行终端 swift
So, this is where swift lives, after you've installed XCode 6 Beta: /Applications/Xcode6-Beta.app/Co ...
- linux基础知识1
1. 硬盘分区 分区类型:主分区,扩展分区.逻辑分区: 分区规则: 一个硬盘仅仅能有1到4个主分区: 一个硬盘仅仅能有1个扩展分区: 一个硬盘的主分区和扩展分区最多仅仅能有4个. 扩展分区仅仅能用来包 ...
- window下自己主动备份数据库成dmp格式的bat写法
复制以下的命令到一个txt文本文档,然后改动相应的參数为自己须要的參数,一切完毕之后,将文件保存为bat格式. 这样每次须要备份的时候仅仅须要双击一下这个bat文件.其它的都不用你了,你仅仅须要静静的 ...
- 推断序列的端部的大小C规划
概念 big-endian格式:高字节字符数据被存储在低地址.字数据的低字节存放在高地址. 小尾数格式:相较于大端存储格式,在小尾数格式.低地址存储在字数据的低字节.的是字数据的高字节. 如5A6C中 ...