As it has been mentioned above, a data source for a web
service is an objective model of a data serves. When a web-service handles a
client request it works with data provided by this model.
By default, as a data source model, ADO.NET Entity Framework
or LINQ to SQL is used. These platforms allow us to give access to relational
data without any additional efforts. The only thing you should do to use this
model is to specify it in generic-parameter when you organize inheritance from
a general base class.
However, there are case when it is impossible to use these
approaches. In practice, sometimes you need to use another type of OR/M
platform or to give access to nonrelational data. In this case ADO.NET Data
Services architecture is very flexible.
To create your own data source you should build a simple
class. There is no need to inherit it from standard classes or implement some
interfaces in it. This class should contain public properties which return
objects of type IQueryable<>. This condition is enough to make the model
readable.
An entity passed through web service should have a key
field. This key field is defined automatically if there is "ID" or
"EntityTypeID" name ("EntityType" is a name of an entity).
If a name of a key field differs from the given scheme, it is necessary to mark
entity with DataServiceKey attribute where you need to specify a name of a key
field in its container.
Listing 5 - The key field defining
[DataServiceKey("ID")]
public class Data
{
public int ID { get; set; }
public string Name { get; set; }
}
The described approach allows us to create only readable
data models. In order to be able to modify data in a model, it is necessary to
implement the interface IUpdatable. As a part of this interface there are
descriptions of methods that allow us to apply changes.