ArticleDirectory
Author:Alexj
Translation: Tan shaomin
Original article:Http://blogs.msdn.com/ B /alexj/archive/2010/01/07/data-service-providers-getting-started.aspx
Introduction
Data ServicesCreated onData Service Provider(Data Service Provider), he is responsibleData ServiceCommunication with data sources.
Data ServicesSome built-in providers are provided, and you can also customize data providers.
The obvious problem is:
Why do we need to customize the data provider?
Creating a custom data provider is very meaningful and you will get huge benefits. You can:
LOn the following clientProgram, Query and operate your data
NWPF
NWinforms
NSilverlight
NAnd so on.
LDirectly query and manipulate your data in a browser;
LUseJavascriptOrJquerySuch framework programs query and manipulate your programs;
LUseWorkbookSuch a data analysis tool to query your data;
LAnd so on.......
However, when you prepare customData Service ProviderWe recommend that you read the following content before, because we have provided some built-in solutions.
Entity Framework (Entity Framework)
If you plan to useEntity FrameworkBuild a data access layer and build yourData ServiceSo you do not need to customizeData Service Provider.
Data ServicesYou have built-inEntity Framework.
Now you can use the strongly typedObjectcontextObject ConstructionData Service, Like this:
Public class northwinddataservice:
Dataservice <northwindentities>
Example aboveCodeMedium,NorthwindentitiesYesEntity FrameworkGenerated strong typeObjectcontextClass.
LINQ to SQL
If yourData ServicesUseLINQ to SQLAs a data access layer, you can refer to this project:
ADO. NET data services iupdateable implementation for LINQ to SQL
This project provides sample code to guide you to implement a strongly typedDatacontextClass, which implementsIupdatableInterface. In this way, you can useEntity FrameworkBuild in the same wayLINQ to SQL.
Public class northwinddataservice:
Dataservice <northwinddatacontext>
Reflection provider (Reflection provider)
If you use a custom class to provide the data source, and these classes contain some return types:IqueryableInterface properties, like this:
Public class mydatasource
{
Public iqueryable <product> Products {get {...} }
Public iqueryable <categories> categories {get {...} }
}
Then the built-in reflection provider can automatically provide read-only data services and inferResourcesets, Type, and attribute.
Of course, you can alsoIupdatableInterface to support the write function.
Public class mydatasource: iupdatable
This feature is based onLINQ to SQL.
When must I customize the data provider?
In common scenarios, the reflection provider is a good choice, but it also has some restrictions:
1,It must be static, and your service is fixed;
2,There must be a factCLRClass to describe the resource type, it is likely that you do not have this class;
3,You must haveIDAttribute or{Type} IDIn this way, the property of the name serves as your key;
4,You needCLRAll relevant attributes of the class should be made public;
5,In terms of stream and paging control, you do not have much customization capability;
6,You cannot obtain some advanced functions, suchOpen typesFeature, which allows youOpen PropertiesThere are more options.
7,Some details are difficult to customize, for example, you cannot easily record requests, or modify metadata and rename attributes;
8,And so on.......
If these problems are what you care about, you must customize them.Data Service ProviderNow......
Create a custom data provider series tutorial
In this series of tutorials, we will show a lotDSP (Data Service Provider)Interface implementation and application scenarios.
1,Overview
2,IserviceproviderAndDatasourcesService provider and Data Source;
3,IdataservicemetadataproviderMetadata provider;
4,Minimal runtime service;
5,Query;
6,Interactive Query;
7,Data update;
8,Link
9,Dynamic type
More tutorials will be provided in the future
10,Etags
11,Subscription support;
12,Data Stream
13,Advanced paging Function