The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








Latest Diggs - Programming

Internet Blogs - Blog Top Sites

Site Hits

Total: 2,502,635
since: 19 Jan 2005

LINQ to REST - A much better name for Astoria

posted Tue 11 Dec 07
Before reading on, check out Andy Conrad's first blog post called LINQ to REST.

Basically here's the flow of what he's talking about:

  1. Define your data source. This is most commonly going to be an Entity Framework source such as a SQL Server or Oracle database. But remember, from my previous blog post, you can use any queryable data source with a little effort. This is huge, huge, huge. Did I mention it was huge?
  2. Once you've got your data source (either an EF or your own queryable object model) create an ADO.NET Data Service using VS 2008.
  3. What you get is a data service with a code-behind file that has a parameter missing from its generic definition. That parameter should be the name of the queryable data source that is being exposed by the ADO.NET Data Service.
  4. Once you've got your data service defined, build it and hit the service a couple of times. The ADO.NET RESTful URL query syntax can be found here. This is a word doc that contains the usage patterns for Astoria, so you can download it right from the link in this post.
  5. Once you're sure that it's working and that it's serving up data properly, and you've tested both read and write scenarios (remember that with this CTP all entities start out as hidden, so you need to write code to expose them, as shown below)

    public static void InitializeService(IWebDataServiceConfiguration config)
    {
        config.SetResourceContainerAccessRule("*", ResourceContainerRights.All);
    }

  6. Now you're going to want to create a client library. While you can access ADO.NET Data Services directly using your favorite XML over HTTP tool, or even your favorite ATOM/APP client library - it's much easier if you know you're going to be consuming the service from a .NET client - ADO.NET Data Services come with their own client library.
    1. The first step in creating the client is generating the local models. Keep in mind that this is not remoting, there is no back-and-forth marshalling. You're sending messages over XML and receiving data over XML, and those payloads have C# object counterparts. To generate the local model, you use the webDataGen.exe application (at least in this CTP). Here's a sample of its invocation: (you can find this file in %ProgramFiles%\Microsoft ASP.NET 3.5 Extensions)
      webdatagen /uri:http://localhost:12345/MyData.svc
            /mode:ClientClassGeneration /language:CSharp /outobjectLibrary:ClientLibrary.cs
    2. Now just add that CS file to your client project and add a reference to Microsoft.Data.WebClient
  7. Your client can now consume the data exposed by the ADO.NET Data Service. The payload format is now completely irrelevant to the smart client (though you'll want to use JSON when consuming the service from Ajax). You can now write queries that look like this:

    var accountsList = from account in entityClient.Accounts orderby account.Name select account;
  8. Enjoy!

I'm working on a bunch more samples, but I agree with Andy Conrad here - using LINQ to consume the ADO.NET Data Services client library which is hitting an ADO.NET Data Service in the back-end, exposing either an EF model or a custom queryable object model. For people like me, this triggers the pleasure center of my brain directly.

I'll leave you with one more thought... what are you going to want to use as your data source for your MVC application? An entity model that is jammed directly into your web application, or, what if instead you consumed the ADO.NET Data Service client library and wrote "LINQ to REST" queries against a loosely coupled back-end data source?

p.s. I know you're thinking "What happens if the entity model changes for the back-end service?". With this CTP, you now have the ability to refresh the entity model from the database schema. Re-run the webdatagen command line tool to rebuild the client library, and then you just need to tweak your client code to have the new property names, etc.

tags:        

links: digg this    del.icio.us    technorati    reddit




Tag Related Posts

CLINQ v1.1.0.0 Released!

Fri 02 May 08 5:38 P GMT-05
tags:          

LINQ to REST - A much better name for Astoria

Tue 11 Dec 07 1:23 P GMT-05
tags:        

ASP.NET 3.5 Extensions Preview Released

Mon 10 Dec 07 2:10 P GMT-05

Unexpected and Unsafe behavior in LINQ

Wed 14 Nov 07 8:09 P GMT-05
tags:    

Continuous LINQ - Can I write games with it?

Mon 13 Aug 07 3:09 P GMT-05
tags:        

Continuous LINQ

Mon 06 Aug 07 1:21 P GMT-05
tags:    

Dynamic, Observable LINQ Views

Tue 31 Jul 07 1:21 A GMT-05
tags:        

Astoria and the Semantic Web

Mon 16 Jul 07 3:47 P GMT-05

Silverlight and Astoria - First Impressions

Mon 04 Jun 07 1:40 A GMT-05
tags:    

Installing Orcas Beta 1 - VMware Style

Mon 23 Apr 07 12:16 P GMT-05

Visual Studio "Orcas" - March CTP is Available

Wed 28 Feb 07 12:28 P GMT-05
tags:            

Objective-C Categories vs C# 3.5 Language Extensions

Mon 26 Feb 07 1:05 P GMT-05
tags:                

DLinq vs the ADO.NET Entity Framework

Fri 23 Jun 06 4:01 P GMT-05

WPF/XAML and LINQ - A match made in heaven

Tue 06 Jun 06 11:32 A GMT-05
tags:                  

Language Extensions in C# 3.0

Wed 31 May 06 2:17 P GMT-05

Lambda Lambda Lambda

Sun 21 May 06 1:01 A GMT-05

The Adventures of LINQ (Not Zelda)

Fri 19 May 06 11:21 P GMT-05
tags: