My code just went SubSonic.

I absolutely love the the goodness which is SubSonic 2.0.3 (2.0.4 on it's way). It's basically a way of automating most of your mundane day to day Database tasks (CRUD - Create, Read, Update, Delete) by using it in a form of native objects.

Example time:

        NxsFINExpense ExpenseClaim = new NxsFINExpense();
ExpenseClaim.Amount = Convert.ToDecimal( dtbleResult.Rows[0][1] );
ExpenseClaim.Description = dtbleResult.Rows[0][2].ToString();
ExpenseClaim.ReceiptDate = Convert.ToDateTime(dtbleResult.Rows[0][0]);

Basically there is a table in my Database called "nxsFIN_Expenses" and each of the properties found on the ExpenseClaim Class is in fact a field within the table (respective type setting also associated via Convert casting).

The part that I love the most is "ExpenseClaim.Save()" which pretty much kills all efforts to writing the "INSERT INTO" bloated SQL Query. This is the kind of magic I've come to embrace inside the .NET community in that, basically everyone's just as lazy as me and would prefer to focus on hard-logic instead of basic CRUD's for example.

I have to say, in the my old Coldfusion circle's we really didn't have anything this automated. I think the closest I've seen probably is "Model-Glue: Unity"  Framework apparently when I last spoke to Sean about it, he stated it cained Ruby-on-Rails (Sean's wise and if he says it did, well I'll assume it did!).

Combine SubSonic with Visual Studio 2008, SQL Express and overall I have a nice warm fuzzy glowing feeling about my progress so far. Whom knows, with this ExpenseClaim .NET application I'm writing I may even get my expenses lodged in-time from here on out.

All thanks to SubSonic's productivity gains (did I oversell that?)

Points to note:

  • So far my entire development environment is costing $0 (i.e assuming I didn't work for Microsoft).

  • SubSonic has some minor issues, like you have to update the Builder.abp file every time you make a database change (to ensure that the framework reflects the database appropriately. I had Namespace errors when I didn't do this).

  • You need to pay attention to the "Getting Started" videos, as it can be a bit of a pain to setup.

  • I'm guessing with complex Database(s) things could get a bit un-nerving (feel free to shoot this point down as I'm not locked into that belief).

  • LINQ + SubSonic appear to play well with one another, so I'll explore this at a later date.

  • It has a really cool trick (this will get it the ladies). In that it will take a plural (Categories) and rename it to (Category) when dealing with singular references (ie ActiveRecord). Doesn't that make you feel gooey inside, reading this? damn straight.

  • I think SubSonic and I should kiss, you know.. to break the tension.. (Simpsons Movie fans will relate to that joke heh).

Next.. bolting on the Silverlight GUI.

Comments (11)

  1. With VS2008, why did you choose subsonic over LINQ to SQL??

    using (ExpenseDataContext context = new ExpenseDataContext())


        ExpenseClaim newClaim = new ExpenseClaim


             Amount = 15.00,

             Description = "Foo",

             ReceiptDate = DateTime.Now,





  2. Garry Trinder says:


    I was looking at alternatives to LINQ on the market and happened to stumble upon this a while back (earlier this year).

    I like both, don’t get me wrong but wanted to see what all the fuss was about SubSonic and opted for it in this project.

    I’m experimenting with my .NET youth.. it’s an akward phase in my life hehehehe.


  3. Hey Scott, we built a code generator for CF (has Flex 2 now as well) which, essentially, accomplishes the same thing. It hasn’t been released but the implementation is like this:

    <cfset myFavorites = application.cfcs.db.favorite.view(PlayerID=session.user.PlayerID) />

    You can pass any of the table columns in to filter the results. Saving is just as simple:

    <cfset application.cfcs.db.favorite.create(PlayerID=session.user.PlayerID, FavoriteID=player.PlayerID[1]) />

    Ignore the values being passed in. Those are from implementations on a live site right now.

    To the .NET world, I haven’t used Subsonic but CodeSmith generates some pretty nice code and the templating makes it even yummier! πŸ™‚

  4. Steven Nagy says:

    So what does SubSonic give that other OR/M doesn’t? Do you think it has advantages over nHibernate or Rhino? Do the objects play well with ObjectDataSource (which in my mind is an absolute necessity for any OR/M in .Net)?

    I guess I’m asking, what sets it apart from other OR/M software, including DLINQ?

  5. Yo Scott, SubSonic ROCKS! I haven’t fully reviewed the underlying code but within 30 minutes I had a new site (side project) DAL rockin’ (with the on-the-fly [buildProvider] method). Using the DAL method, it was just as fast (register the tool, run it).

    I quickly converted 1 page to use Subsonic and, besides changing my user control from expecting string[] to IDataRead, it worked off the bat. FWC.mytable.Fetch()! πŸ˜€

    I’ll just clarify my excitement real quick. CodeSmith has produces a lot of code and, as noted, the templating is pretty nice. Our lead .NET guru handles this though and when I tried…well…let’s just say it wasn’t nearly as easy as SubSonic. Now I can rock DAL’s and knock out projects super fast. Thanks for pointing this out!

    – Highly Pleased

  6. Garry Trinder says:


    You just had what i call a "come to jesus" moment πŸ˜›

    Yes, there is LINQ, yes there are alternatives and there appear to be a large amount of ways in which you could use SubSonic.. but.. it takes what you’ve just done, home-grown experimentation.

    Experimentation costs nothing πŸ˜›

  7. kevin says:

    good to see another SubSonic user!

    I run and have a few subsonic tutorials/posts over there which you can find here:

    Also, is a good start to get things going and the forums are good as well.

    The forums is a project called SubSonic Forums (aka "community) and is a "eat your own dog food project" – meaning it’s a work in progress but its a good example of a web app built using SubSonic. that project is available for download here:

    also, I have a subsonic/rest (json/xml) and jquery vidcast coming this week as well. just another great way to enhance your dev life πŸ™‚

    keep playing with subsonic! it’s really a great tool.

    tip – you will eventually want to generate your Model code via the subsonic generators. the builder is great (and super fast) for getting things going but it’s a bit of a perf hit versus compiled class library which you’ll want to use in prod of course. Watching the subcommander tool video is a really cool way to get subsonic integrated into VS.NET

  8. @scott

    LMBO @ "come to Jesus" moment. πŸ˜€


    Thanks for the links dude. I’ll def’ be looking into things more.

    I would also use the generated code. When I read the buildProvider would do an on-the-fly I had to try to prove it wrong. πŸ˜€ (I didn’t) lol

  9. hasan says:


    does it work with Vs.Net 2005?

    thanks in advance

  10. ldadams says:

    Yes it most def. works with 2005. Actually it hasnt been ported to the 3.5 framework yet…. 2.0.4 is coming.  SubSonic is a great product.

Skip to main content