Export (0) Print
Expand All

Entity Framework Provider (WCF Data Services)

Like WCF Data Services, the ADO.NET Entity Framework is based on the Entity Data Model, which is a type of entity-relationship model. The Entity Framework translates operations against its implementation of the Entity Data Model, which is called the conceptual model, into equivalent operations against a data source. This makes the Entity Framework an ideal provider for data services that are based on relational data, and any database that has a data provider that supports the Entity Framework can be used with WCF Data Services. For a list of the data sources that currently support the Entity Framework, see Third-Party Providers for the Entity Framework.

In a conceptual model, the entity container is the root of the service. You must define a conceptual model in the Entity Framework before the data can be exposed by a data service. The Entity Framework provides tools that automatically generate an object layer based on the conceptual model. The object layer includes entity types and a container class, which inherits from the ObjectContext class. The container class also typically has entity set properties that return an IQueryable collection of entities of the specified type. When you use the Entity Framework provider, you simply supply this container class as the type of the DataService from which your data service derives, as in the following example for a Northwind data service.

public class Northwind : DataService<NorthwindEntities>

For more information, see How to: Create a Data Service Using an ADO.NET Entity Framework Data Source (WCF Data Services).

Dd673932.note(en-us,VS.100).gifNote:
When you use the Code First feature of Entity Framework 4.1 to define your data model, you define a context class that derives from the DbContext class instead of from the ObjectContext class. However, you cannot supply a DbContext-derived class directly to the data service. For an example of how to use a Code First-based Entity Framework model as the provider for your data service, see the topic Using Entity Framework 4.1 Code First with WCF Data Services in the TechNet Wiki.

WCF Data Services supports the optimistic concurrency model by enabling you to define a concurrency token for an entity. This concurrency token, which includes one or more properties of the entity, is used by the data service to determine whether a change has occurred in the data that is being requested, updated, or deleted. When token values obtained from the eTag in the request differ from the current values of the entity, an exception is raised by the data service. To indicate that a property is part of the concurrency token, you must apply the attribute ConcurrencyMode="Fixed" in the data model defined by the Entity Framework provider. The concurrency token cannot include a key property or a navigation property. For more information, see Updating the Data Service (WCF Data Services).

To learn more about the Entity Framework, see Entity Framework Overview.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft