Database Reference
In-Depth Information
WCF Data Services
WCF Data Services, formerly known as ADO.NET Data Services, enables the creation and consumption
of OData services. OData, the Open Data Protocol, is a new data-sharing standard that allows for greater
sharing of data between different systems. Before it was called WCF Data Services, ADO.NET Data
Services was one of the very first Microsoft technologies to support OData with Visual Studio 2008 SP1.
Microsoft has broadened its support of OData in products such as SQL Server 2008 R2, Windows Azure
Storage, and others. This section discusses how to use WCF Data Services to connect to and query your
SQL Azure database.
Creating a Data Service
First you need to create a data service. Follow these steps:
1.
Create a new ASP.NET web application, and call it WCFDataServiceWebApp.
(You can host data services a number of different environments but this
example uses a web app.)
2.
The next step in creating a data service on top of a relational database is to
define a model used to drive your data service tier. The best way to do that is to
use the ADO.NET Entity Framework, which allows you to expose your entity
model as a data service. And to do that, you need to add a new item to your
web project. Right-click the web project, and select New Item. In the Add New
Item dialog, select Data from the Categories list, and then select ADO.NET
Entity Data Model from the Templates list. Give the model the name
TechBioModel.edmx , and click OK.
3.
In the first step of the Data Model Wizard, select the Generate From Database
option, and click Next.
4.
The next step is Choose Your Data Connection. Click the New Connection
button, and create a connection to your SQL Azure database. Save the entity
connection settings as TechBioEntities , and then click Next.
5.
The next step of the wizard is the Choose Your Database Objects page. Select
all the tables. Note the option that is new to ADO.NET Entity Framework
version 4.0, which pluralizes or singularizes generated objects names. If you
leave this option checked, it comes into play later. Leave it checked, and click
Finish.
6.
The Entity Framework looks at all the tables you selected and creates a
conceptual model on top of the storage schema that you can soon expose as a
data service. In Visual Studio, you should see the Entity Framework Model
Designer with a graphical representation of the tables, called entities , and their
relationships. Close the Model Designer—you don't need it for this example.
7.
What you need to do now is create the data service on top of your data model.
In Solution Explorer right-click the web application and select Add, then select
New Item. In the Add New Item dialog, select the Web category, then scroll
down the list of templates and select the WCF Data Service template. Enter a
name of TechBioDataService the click Add, as shown in Figure 6-10.
Search WWH ::




Custom Search