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:

  1. It is static, i.e. the shape of the service can’t evolve over time.
  2. It needs CLR classes for each ResourceType, which you might not have.
  3. It needs to find Id or {Type}Id properties to use as keys.
  4. It blindly exposes all public properties of the CLR classes.
  5. It gives you less control over streaming or paging.
  6. You can’t take advantage of advanced features like Open Types, which allows resources to optionally include more Open Properties.
  7. You have less control, for example you can't log requests as easily or modify metadata or rename properties
  8. 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的更多相关文章

  1. 自定义Data Service Providers

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

  2. POJ 3911:Internet Service Providers

    Internet Service Providers Time Limit: 2MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I ...

  3. WCF Data Service

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

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

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

  5. Laravel 之Service Providers

    Service providers are the central place of all Laravel application bootstrapping. Your own applicati ...

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

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

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

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

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

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

  9. 调用WCF Data Service的几点Tips

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

随机推荐

  1. 设计Mysql索引的原则

    1. 搜索的索引列,不一定是所要选择的列.换句话说,最适合索引的列是出如今WHERE 子句中的列,或连接子句中指定的列,而不是出如今SELECT keyword后的选择列表中的列. 2. 使用惟一索引 ...

  2. 【设计模式】Template Method模式

    OO基金会 封装 多态 继承 OO原则 封装变化 多用组合,少用继承 针对接口编程.不针对实现编程 为交互对象的松耦合设计而努力 类应该对扩展开放,对改动关闭 依赖抽象,不要依赖详细类 仅仅和朋友交谈 ...

  3. jvm调音

    jvm性能调优的目地:1)控制jvm的堆栈大小.比方当你的程序年轻代对象在某个时间段产生的比較多的时候,就须要控制年轻代的堆大小. 同一时候还要控制总的JVM大小避免内存溢出 2)控制GC的行为. G ...

  4. Java OCR tesseract 图像智能字符识别技术 Java代码实现

    接着上一篇OCR所说的,上一篇给大家介绍了tesseract 在命令行的简单用法,当然了要继承到我们的程序中,还是需要代码实现的,下面给大家分享下java实现的例子. 拿代码扫描上面的图片,然后输出结 ...

  5. 谈谈CListCtrl 扩展风格设置方法-SetExtendedStyle和ModifyStyleEx 比較

    谈谈CListCtrl 扩展风格设置方法 --------------------------------------SetExtendedStyle和ModifyStyleEx 比較 对于刚開始学习 ...

  6. android横竖屏控制

    代码中设置activity屏幕为全屏,并设置横竖屏状态 getwindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowM ...

  7. hdu4190 简单的二分法

    题意是 有n个城市,m个投票箱.接下来n个城市人口数,每一个投票箱都不能为空.计算最后投票箱的容量必须达到多少,才干满足须要. 每一个城市的人必须仅仅能将票投到自己城市分得得投票箱中.要是容量最小箱子 ...

  8. Memcached全面剖析–5. memcached的应用和兼容程序

    作者:长野雅广(Masahiro Nagano)  原文链接:http://gihyo.jp/dev/feature/01/memcached/0005 我是Mixi的长野.memcached的连载最 ...

  9. Linux查找多个类似,但不同的名称和重命名文件

    受试者被认为是百度侧面问题,Linux称号:寻找core.1.core.2....形式命名的文件,然后改变这些文件的名称bak.core.1.bak.core.2,...... 首先,你应该找到这些文 ...

  10. Ribbon 和 Eureka 积分

            Ribbon 这是 Netflix 云服务的中间层宣布开放源代码项目,它的主要功能是提供客户机端软件的负载均衡算法,将 Netflix 中间层服务一起. Eureka 是 RESTfu ...