Customizing the Data Service Providers

Source: Internet
Author: User

Customizing the Data Service Providers

AlexJ

Translation: Shaomin

Original link: http://blogs.msdn.com/b/alexj/archive/2010/01/07/data-service-providers-getting-started.aspx

Brief introduction

Data Services is built on the data service Provider, which is responsible for communication between the data service and the source.

Data Services has built-in providers, and also allows you to customize the provider.

So the obvious question is:

Why customize a data provider?

Creating a custom data provider makes a lot of sense and you'll get huge gains that you can:

L Query and manipulate your data in the following client programs

N WPF

N WinForms

N SilverLight

N, wait.

L Query and manipulate your data directly in the browser;

• Use a framework program such as JavaScript or jquery to query and manipulate your program;

l Use data analysis tools such as PowerPivot to query your data;

L ... etc...

But before you prepare to customize the data Service provider, it is recommended that you read the following, as we have provided some built-in scenarios.

Entity Framework

If you plan to use the Entity Framework to build your data service, then you don't need to customize the Provider.

Data Services already has a built-in database provider for the entity Framework.

Now you can build the data Service very simply with a strongly typed ObjectContext object, like this:

public class Northwinddataservice:

Dataservice<northwindentities>

In the example code above, NorthwindEntities is the strongly typed ObjectContext class you generated using the Entity Framework.

LINQ to SQL

If your data Services uses LINQ to SQL as the access layer, then you can refer to this project:

ADO Data Services iupdateable implementation for LINQ to SQL

This project provides example code that guides you through the implementation of a strongly typed DataContext class that implements the IUpdatable interface. This allows you to build LINQ to SQL data providers in the same way as the Entity Framework.

public class Northwinddataservice:

Dataservice<northwinddatacontext>

Reflection Provider (Reflection provider)

If you use a custom class to provide a data source, and these classes contain properties that return types are IQueryable interfaces, like this:

public class myDataSource

{

Public iqueryable<product> Products {get {...}}

Public iqueryable<categories> Categories {get {...}}

}

The built-in reflection provider is able to automatically provide read-only data services that infer resourcesets, types, and attributes.

Of course, you can also support the write function by implementing the IUpdatable interface.

public class Mydatasource:iupdatable

This attribute is based on the functionality mentioned above in LINQ to SQL.

When do you have to customize the data provider?

In a typical scenario, the reflection provider is a good choice, but he also has some limitations:

1, he must be static, your service is fixed;

2. There must be a fact that the CLR class exists to describe the resource type, most likely you do not have this class;

3, you must have an Id attribute or have a {type}id name attribute as your key;

4. You need to expose all relevant properties in the CLR class;

5, in the flow and paging control, you do not have much customization ability;

6. You can't get some advanced features, such as the open Types feature, which allows you to have more options on the open properties.

7, some details you are also difficult to customize, such as you can not easily record requests, or modify metadata and rename attributes;

8, etc...

If these questions are your own, then you have to customize the data Service provider ...

Create a series of custom data providers tutorials

In this series of tutorials, we will present a large number of DSP (Data Service Provider) interface implementations as well as application scenarios.

1. Overview

2, IServiceProvider and datasources service providers and data sources;

3, idataservicemetadataprovider metadata providers;

4, the minimum operation time service;

5, inquiry;

6, interactive query;

7, data Update;

8. Relationship

9. Dynamic type

More tutorials will be included in the future

10, Etags

11, subscription support;

12. Data Flow

13. Advanced Paging function

Customizing the Data Service Providers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.