Hi there.
Renamed in the .Net Framework 4.0 from “ADO.net Data Services” to the new – more snappy – “WCF Data Services”, today I’m going to take a closer look at what drives this latest version. If you look at the release notes there are a number of additions (as well as obviously using the much better Entity Framework v4):
-
Data binding,
-
Counting entities in an entity set,
-
Server-driven paging,
-
Query projections,
-
Custom data service providers,
-
Streaming of binary resources.
To find out what else is new check out What’s New in WCF Data Services. Also you might want to look at Getting Started with WCF Data Services http://msdn.microsoft.com/en-us/library/cc668810.aspx
To start, I am going to take a look at the server-driven paging since paging has typically been one of those areas of functionality where, if implemented poorly, can really degrade performance of a database or website.
What you’ll need:
- Visual Studio 2010 Service Pack 1
- SQL Server 2008 R2 [any edition] with Service Pack 1 – although this should in theory work fine with SQL Server 2005 and 2008.
- AdventureWorks Sample Database
We’ll be using the old favourite AdventureWorks sample database so that we have some data preloaded. You can obtain the latest version for SQL Server 2008 R2 from Codeplex at the following location: http://msftdbprodsamples.codeplex.com/releases/view/55926. The installer does a great job of installing the samples for you, for this article we’re just going to use the OLTP demo database, so you can ignore the others for now. See the screenshot below, which is how it should look after it is installed (via SSMS):
If you’re not too sure how to go about setting up an Entity Framework data source with AdventureWorks, check out this article from MSDN.com – though please note it is written for use with Visual Studio 2008, not Visual Studio 2010 Service Pack 1: http://blogs.msdn.com/b/adonet/archive/2008/06/18/tutorial-entity-data-source-control.aspx
What we’re going to do is create a new Solution with an ASP.net Web Application. Once it is created, add a Class Library to the solution and then add a new Entity Framework data model. I’ve called mine ‘AdventureWorksModel’ as you can see in the screenshot. Choose to generate it from a database, and select the AdventureWorks2008R2 database.
When I tried to generate the Model, I received the following error message: ‘Unable to generate the model because of the following exception: ‘The table ‘AdventureWorks2008R2.Production.Document’ was referenced by a relationship, but was not found.’
To work around it, I unselected all the tables in the ‘Production’ schema, and just added the remaining tables instead. I’ll take a look at this error later to see if I can find out where the errant relationship is causing problems.
At any rate, you should now have a half decent model to play with:
..moving on. In your ASP.net Web Application project, make sure you add a reference to the DataAccess class library. Then, it’s time to create the data service:
-
In Solution Explorer, right-click the name of your ASP.NET project, and then click Add New Item.
-
In the Add New Item dialog box, select WCF Data Service.
-
For the name of the service, type AdventureWorksDataServices.
Visual Studio will show you some generated code. You’ll need to add the name of your Entity Framework Data Context in the definition of the WCF Data Service, like below:
public class AdventureWorksDataServices : DataService<AdventureWorksModelContainer>
In Part 2, we’ll be looking at how to configure the WCF Data Service and then how to use some of the new features.
Part 2 will be coming soon.
2 thoughts on “WCF Data Services Walkthrough : Part 1 (Setup)”
Did you ever find out what the root cause of the message
“Unable to generate the model because of the following exception: ‘The table ‘AdventureWorks2008R2.Production.Document’ is referenced by a relationship, but cannot be found
.”
was? I also get that message.
I suspect it is related to the associated filestream used (see the sql create script for this table).
Going to try and complete the next part (Part 2) and hopefully can address that issue.. hopefully..