Tutorial: ADO.NET Data Services

This Tutorial provides information on how to configure and use ADO.NET Data Services in your projects.
Example source code in C# is provided for each of the steps so that you can quickly understand how to get started.

Part 1 - Setting up the projects [Source Code] [Blog Link]

This part provides the fundament for all following parts.
It shows how to configure a web project, and two console projects for using ADO.NET Data Services.
  • Create a new ASP.NET Web Application
  • Add a new item of type ADO.NET Data Service

  • The ADO.NET Data Service is now generated using a standard template

  • Add two standard console projects to the solution (for Client and Host)


Part 2 - Using the Entity Framework
[Source Code] [Blog Link]

Learn how to use the Entity Framework in combination with ADO.NET Data Services.
This is the most easy and quickest way to provide access to Data Sources.

  • Add a new Item of type ADO.NET Entity Data Model
  • Generate a new model from the AdventureWorks DB in your SQL Server

  • Change the Data Service code and add as type the newly generated AdventureWorksEntities


Part 3 - Host & Client Projects
[Source Code] [Blog Link]

Learn how to host an ADO.NET Data Services outside of IIS and how to create a proxy to consume it.

  • Open the Host Console project that was created before and add a Reference to the ADO.NET Data Service project
  • In the Main function implement a DataServiceHost object and use as type ExampleDataService

  • Add an application configuration file and configure the connection string to the AdventureWorks data source
    (you may copy the ConnectionStrings section from the WebConfig file of the ADO.NET Data Service project)
  • Open the Client Console project that was created before and add a Service Reference to the ADO.NET Data Service
    project (click on Discover), which will auto-generate some proxy classes
  • In the Main function implement the proxy class AdventureWorksEntities and add a function call to a Read method

  • Implement the Read method by using a simple LINQ query that retrieves Product data from the AdventureworkEntities
    proxy and that display the results

  • Run the application using as Startup projects the Host and the Client projects
  • When entering ‘Read’, the ADO.NET Data Service will be queried and a list of all products will be displayed


Part 4 - Custom Data Sources 1/2 [Source Code]
[Blog Link]

This part describes how to replace the Entity Framework part with custom Data Sources (for example POCO business objects).
By doing this, you will get the full functionality of ADO.NET Data Services but the flexibility to use you own custom Data Sources
(Object in Memory, Oracle DB, Data Cubes, Files, etc…).

  • Open the ADO.NET Data Service project and add some new classes that will serve as structure for your custom Data  Source
    (for example  Invoice, InvoiceLine, Thirdparty and BusinessEntities)
  • The BusinessEntities class serves as container for the different custom entities that you want to expose, they are initialized
    in the constructor for the example and must be accessible via public IQueryable properties

  • Add a new item of type ADO.NET Data Service
  • Change the Data Service code of the new ExampleDataService2 and add as type the custom BusinessEntities


Part 5 - Custom Data Sources 2/2 [Source Code]
[Blog Link]

The last part described how to replace the Entity Framework with custom Data Sources.
This part goes into more detail concerning the necessary modifications in the Host & Client projects.
At the end of this part you will have a fully working ADO.NET Data Service based on your own custom Data Structure and Data Sources.

  • Open the Client project and add a new Service Reference to the ExampleDataService2
  • Change the implementation in the Main function and add a new proxy to the new ADO.NET Data Service
  • Change the implementation in the Read function and add a two new function calls in dependency of the user input

  • Add the implementation of the new ReadEF and ReadCustom functions so that the correct proxy is used to query for data
    and display it in the console

  • Open the Host project and modify the Main function so that both ADO.NET Data Services are hosted on different addresses

Find further explications and a more detailed step-by-step guide on my Blog:

http://jasondeoliveira.com

Last edited Sep 14, 2010 at 12:40 PM by JasonOliveira, version 14