"Subsonic" for Services found: Subsonic 3 + ADO.NET Data Services (Astoria)

About a month ago if you asked me what was big in my dev world (in other words what are you looking for).  I would have promptly told you that I was looking for the "Subsonic" of services. In other words I wanted to create a database and hook a connection string and have everything generated for me... I want drop dead simple.

Astoria was as close as I could get, but it didn’t quite achieve what I was looking for. Don’t get me wrong, it’s easy enough. I’m just not sure what I think of EF yet which is not to say that I don’t like it... just that I sometimes want something simple. Rob Teixeira has noted that for some there are "too many knobs." I’d have to say I’m somewhat in that camp (although I’m not very informed either and I’m not a huge lover of Linq to SQL either).

I love the simplicity of Subsonic. I really do, and I really want to leverage something that simple for building a Data Service. Rob Conery (I love Rob... You can have ScottHa or Haacked... I’ll take Conery... He’s my hero!) recently released a preview of Subsonic 3.0 which is fully Linq-Queryable and also has the normal Subsonic Query engine... it’s the best of all worlds (except it’s not backwards compatible).

Since my readings from John Papa’s book taught me that Astoria doesn’t need an EF model that regular classes could work, and I have a personal project that could use an easier more service friendly manner of editing/viewing data, I decided to try this out.

Preview 1 was an abysmal failure. Well, to be fair I quit because Preview 2 came out. I stuck with Preview 2 and earlier today I got it all working.

  1. Here’s how to do it. #1 follow Rob’s instructions (on any of the links I’ve provided and get Subsonic stuff working). I did all this in a separate DLL project.
  2. Create a regular web site (or web project)
    1. make sure there is a connection string in the web.config that has the same name as the "ProviderName" variable in the _Settings.tt file
    2. Add an ADO.NET Data Service to your web site/project.
    3. Add this attribute to your service class
      [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] 
    4. Next set the DataService T type to the "DB" class of your Subsonic generated class. It will look something like this:
      public class NorthwindService : DataService<Northwind.DB>
  3. Tada! You are done...

A couple notes

Both Preview 1 and 2 build a class model that exposes an object/class called "DB." Think of this class as "Context" (even though EF and Linq2SQL context classes do a lot more). For the sake of Astoria, you just need a class that exposes all your entities in an IQueryable manner (which "DB" will do).

I ran into one error that was messing me up. If you make name of your Primary Key IDs "ID" then everything in the above worked fine. If it didn’t I am going to provide an alternate set of templates (TT files) for you to use. What’s missing is that Astoria expects an "ID" property. You can get around this by tagging each entity class with

[System.Data.Services.Common.DataServiceKey("{tablename_id}")]  

This also means that you have to include the System.Data.Services.Client.DLL in your Subsonic project.

My TT files (based on Preview 2)

I added a new variable in _Settings.tt that let’s you turn off the attribute used for setting the PK in your entity classes. It’s called "EnableForUseWIthAstoria." Here they are :

Closing thoughts

With all this in hand you should be able to create Astoria Services with any DB that Subsonic supports (which I believe is a larger number than what EF currently supports.

Additionally, like Rob Conery, I want to stress this is all experimental. This code might run off with your wife, children, it might decide to use your PC late at night to play video games thereby increasing your electricity, etc. (in other words this is all experimental right now... have fun with it, and be careful ... you probably don’t want to use it for live/mission critical code).

Print | posted on Tuesday, November 18, 2008 2:02 PM

Feedback

# re: "Subsonic" for Services found: Subsonic 3 + ADO.NET Data Services (Astoria)

left by Martin Nyborg at 11/18/2008 5:55 PM Gravatar
Nice I was thinking about doing the same for a Silverlight spike, but you got there first :-)

Anyway nice proof of concept. Can't wait for Robs drop 4.

Robs is my hero to, maybe we could start a fan club.

# re: "Subsonic" for Services found: Subsonic 3 + ADO.NET Data Services (Astoria)

left by Haacked at 11/18/2008 11:51 PM Gravatar
No, you can have ScottHa. Conery's all mine. Mine!

;)

# re: "Subsonic" for Services found: Subsonic 3 + ADO.NET Data Services (Astoria)

left by Rob Conery at 4/5/2009 4:22 AM Gravatar
Hero? What? Wait til my wife sees this..

Jay I'd love to put you on commit so we can nail the Astoria thing. If you're game send me your google login and don't tell Phil :)
Comments have been closed on this topic.