CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

David Hayden [MVP C#]

         .NET Tutorials, Patterns, and Practices

Getting Started with ADO.NET Data Services

At the Sarasota Visual Studio 2008 InstallFest I showed off a number of ASP.NET 3.5 Extensions CTP Features. One was ASP.NET Dynamic Data, which I have talked about in several posts:

 

Another was ADO.NET Data Services.

For those of you who haven't played with ADO.NET Data Services, you owe yourself a quick 5 minute look to think about the possibilities. Here is the quick introduction I provided at the Visual Studio 2008 InstallFest.

 

Install the ASP.NET 3.5 Extensions CTP

First things first, swing over to the ASP.NET Website to download and install the ASP.NET 3.5 Extesions CTP, which includes ADO.NET Data Services.

You can find it here: http://www.asp.net/downloads/3.5-extensions/

Note this is a CTP, so common sense applies to what machines you install it on.

 

Create a New ASP.NET Website 

Run Visual Studio 2008 and Create a New ASP.NET Website

 Create ASP.NET Website

 

Add LINQ To SQL Classes and ADO.NET Data Services Items

We need some data, and one of the easiest ways to get data is to add a LINQ TO SQL Classes File to the solution and drag and drop Northwind Tables on it. We also need to add the ADO.NET Data Services Item to the solution as that is what we are trying to test. I called my items, Northwind and NorthwindDataService, respectively.

Hopefully LINQ To SQL is fairly easy to add. ADO.NET Data Services is even easier to add:

Add ADO.NET Data Services 

 

When all is said and done, the solution looks like this:

ADO.NET Data Services Solution

 

Configure NorthwindDataService to use NorthwindDataContext

Open up the NorthwindDataService.cs in the App_Code Folder and change the code to look like below:

 

public class NorthwindDataService :
            WebDataService<NorthwindDataContext> {
            
    public static void InitializeService(IWebDataServiceConfiguration config)
    {
        config.SetResourceContainerAccessRule
            ("*", ResourceContainerRights.AllRead);
    }
    
}

 

Note that I added the NorthwindDataContext and set the access rules to allow access to all the data provided by the NorthwindDataContext in a read-only fashion.

 

Run the Website and Begin Querying

Now you can just run the website and start querying products or anything else in the Northwind Database using REST type URL's.

Fetch ProductID = 1 : http://localhost:1453/WebSite5/NorthwindDataService.svc/Products(1)

Northwind ADO.NET Data Service

 

Fetch the Supplier for the Product : http://localhost:1453/WebSite5/NorthwindDataService.svc/Products(1)/Supplier

ADO.NET Data Services - Supplier 

 

Fetch Products 11 - 20 : http://localhost:1453/WebSite5/NorthwindDataService.svc/Products?$skip=10&$top=10

 

Fetch Name of Product : http://localhost:1453/WebSite5/NorthwindDataService.svc/Products(1)/ProductName/$value

I think I change Chai to Chai2 playing with the database, so your version will probably say Chai :)

 

 

Read the Documentation

Check out the documentation on ADO.NET Data Services for the ASP.NET 3.5 Extensions CTP at:

http://quickstarts.asp.net/3-5-extensions/adonetdataservice/default.aspx

 

Pretty cool stuff...



Comments

Christopher Steen said:

ASP.NET Web Development Toolbox [Via: Chris Brandsma ] WPF WPF/Xaml Web News - 2008/01/08 [Via: rrelyea...

# January 9, 2008 12:26 AM

Noticias externas said:

LINQKit www.albahari.com/.../linqkit.html LINQ Dynamic Query Library http://weblogs.asp.net

# January 9, 2008 3:56 AM

» Daily Bits - January 9, 2008 Alvin Ashcraft’s Daily Geek Bits: Daily links plus random ramblings about development, gadgets and raising rugrats. said:

Pingback from  &raquo; Daily Bits - January 9, 2008 Alvin Ashcraft&#8217;s Daily Geek Bits: Daily links plus random ramblings about development, gadgets and raising rugrats.

# January 9, 2008 9:34 AM

TerryLee said:

概述又开始新一期的推荐系列,总共有10篇。1.ASP.NETPerformanceTips2.CachingImagesinASP.NET3.4ASP.NETAJAXJavaS...

# January 14, 2008 7:40 AM

Jacky_Xu said:

概述

又开始新一期的推荐系列,总共有10篇。

1.ASP.NETPerformanceTips

2.CachingImagesinASP.NET

3.4ASP.NETAJAXJ...

# January 14, 2008 11:49 PM

Man vs Code said:

Michael Sync has written a sample using the new Astoria Silverlight client library. David Hayden posted

# January 15, 2008 7:55 PM

Noticias externas said:

Michael Sync has written a sample using the new Astoria Silverlight client library. David Hayden posted

# January 15, 2008 8:29 PM

MSDN Blog Postings » Project Astoria Links for 1/15/08 said:

Pingback from  MSDN Blog Postings  &raquo; Project Astoria Links for 1/15/08

# January 15, 2008 9:36 PM

Guru Stop said:

It started an email Mohamed Hossam (AKA, Bashmohandes) sent to my company's local office here in Egypt

# February 4, 2008 7:09 AM

VSone - Tag 2 - WCF, SQL Server Compact Edition, System.AddIn, ADO.NET Entity Framework, ADO.NET Data Services ("Astoria") | Code-Inside Blog said:

Pingback from  VSone - Tag 2 - WCF, SQL Server Compact Edition, System.AddIn, ADO.NET Entity Framework, ADO.NET Data Services (&quot;Astoria&quot;) | Code-Inside Blog

# February 17, 2008 12:51 PM

David Hayden [MVP C#] said:

I forgot to mention that while I was at SQLSaturday in Tampa, Florida I ran into some very passionate

# February 19, 2008 9:53 AM
Check out Devlicio.us!

This Blog

Syndication

News

CodeBetter.Com Home