public class SubSonic3: IEnjoyable

Software Update
Image via Wikipedia

A couple of years ago, I heard about a data-layer code generation tool called SubSonic.  At the time, there was a fair bit of confusion about how it was to be categorized - it wasn't really an ORM, after all.  In fact, it was sort of a C# version of Ruby-On-Rails' ActiveRecord.  I played with it a bit, but I set it aside because I didn't have any projects at the time that called for something like this.

Fast forward a couple years, and some things have changed.  SubSonic's founder, Rob Conery, has been hired by Microsoft.  Somewhat surprisingly, this has not meant the end of SubSonic.  In fact, Rob's working on a new release, and it's shaping up to be really, really nice.  This is the first SubSonic release to come out with Linq support, and they look like they were made for one another.

When Rob announced the Subsonic 3 Preview 2 release, I grabbed it and took it for a quick spin.  If you're going to try this release, Rob's done a quick video that walks through a quick install and deployment, and I'd recommend watching it.  Installation couldn't be easier - the readme file lists four simple steps, and if you do everything right, you'll be up and running with scaffolding support for your database in less than five minutes (it takes less than one in the video).

What do you get for your effort?  SubSonic's scaffolding support builds out classes for each table in your database, as well as helpers for all of your stored procs.  The syntax shifts since SubSonic's earlier releases means that SubSonic 3 isn't a true ActiveRecord implementation, but the syntax is very natural and (IMO) productive -- it allows you to express database requests in a really compact form:  (example from Rob's post)

Northwind.DB db = new DB();
var result = from p in db.Products
where p.CategoryID == 5
select p;

foreach (var item in result)
{
Console.WriteLine(item.ProductName);
}
database 2
Image by Tim Morgan via Flickr

There's also support for LINQ queries, and you can batch queries so that multiple queries occur in one call to the database.  Even stored procs get an assist from SubSonic - procs are encapsulated into simple, type-safe function calls that return a reader for the results.  This is a big improvement over traditional data access layers where you'll see tons of repeated code.

Part of the magic comes from the SubSonic assembly, which supplies database-related code that could cut a bunch of repeated code out of your projects all by itself.  That's only part of the picture, though - there's a set of generated files that gives you strongly-typed objects for each of your tables.  The code generation uses T4 templates - see this screencast on the Patterns & Practices site for more on T4.

While simple applications might make use of the generated partial classes as-is, more complex apps are going to want to extend and/or encapsulate these classes, and expose more complete business classes to callers.  There are a number of ways you could do this:

  • Edit the generated code.  This is probably not an approach you'd want to take for a production app, but for a quick prototype, it could work well.  The problem with this approach is that your customizations are subject to breakage as the generated code changes.  If you can limit your changes to extensions (via partial classes), you might stand a chance here; otherwise, you'll want to explore other options.
  • Change the templates.  Since SubSonic is open-sourced, you have access to anything you might want to change.  Better yet, since the templates themselves are copied into your project, any changes you make there will be local to your project.  If your changes can be expressed in the T4 templates, this could be a really good option for you.
  • Encapsulate the generated classes.  I've come to really like working with Rocky Lhotka's CSLA Framework, but the data access parts of these classes freqently end up feeling a little more ponderous than I'd like.  SubSonic is just the thing to fix this - its syntax is crisp and compact, leaving me to focus on writing business code in my CSLA classes.  Personally, I like this model a lot - it builds on the strengths of both projects.

I'd also recommend checking out Rob's webcast on using SubSonic as a REST handler.  There are some other interesting options if you're trying to build a REST interface to your database (Astoria, WCF REST starter kit), but it's a great demonstration of SubSonic's ease-of-use.

Bear in mind that this is a preview release (before beta), so there are some rough edges.  I saw some code generation snafus where I had fields named the same as their tables, and there's a problem with LINQ support that makes it tough to construct a LINQ query using the value of a variable rather than a reference to that variable.  You're going to want to wait for a slightly more mature release before you start doing "real" work with 3.0, but this preview will give you a good indication of what's to come.  There's a lot here to like.

Reblog this post [with Zemanta]

GradSourcing

Green Bay
Image via Wikipedia

There was another great tech event in Columbus last week- the TechColumbus CIOhio 2008 conference. Unfortunately, I wasn't able to attend this event, but I followed along thanks to @bblanquera, @8101harris, and others. According to Dan, one of the topics that came up was GradSourcing. BMW Financial's Jeff Haskett spoke about a program he's put in place to bring new talent into his organization directly out of school.

When I heard about this program, I thought back to my own experience growing a team in Green Bay, WI a dozen or so years ago.  Green Bay was (is?) largely a blue-collar town, and it really didn't attract a ton of IT talent, so when I needed to build a software development team, I found that I had to relocate people to Green Bay or develop talent locally.  Relocating people to Wisconsin, it turned out, wasn't especially easy or cost-effective, so I had to find a way to grow good developers locally.

Continue reading "GradSourcing"

Great post on Generics

If there's one thing I can do...
Image by harold.lloyd (homologous) via Flickr

If you're not comfortable using C# Generics in your code, be sure to check out this great article by Karl Seguin.  It's an easy read, and it covers all the important ideas you'll need to get your head wrapped around these things.

I've mentioned Generics a couple times on this blog - they've been a great resource to me.  I'll admit - it took a little while for me to get comfortable with some of these ideas - especially multiple Generics, but since I've gained an appreciation for their capabilities, I find myself grabbing this tool early and often.

For me, the key to understanding Generics was to use them - as intensively as possible.  I used them in code I was writing from scratch, and then, when I started working with Rocky Lhotka's CSLA Framework, I needed to work with them more.  His framework, in fact, makes very heavy use of Generics - to the extent that I could see someone being put off by the learning curve if they weren't already comfortable with Generics.

Reblog this post [with Zemanta]

Columbus: Can we become a tech center?

I read an awesome post yesterday from a startup founder from Atlanta who's moving his operation's headquarters to California.  As I read about the challenges Atlanta poses to tech startups, I couldn't help but reflect on my own similar experiences.

City of Columbus
Image via Wikipedia

A few years ago, I had a chance to ride along with a software startup company here in Columbus, OH. I wrote our product's first lines of code and grew an incredible team of developers who helped grow the product. Life was challenging, and the path was steep, but we had nowhere to go but up.

Then, funding happened. Our CEO spent tireless days pounding the pavement in central Ohio looking first for Angel funding, then for VC funding. We spoke with a number of firms in ever-widening concentric circles around Columbus, but we never found anyone in this area who was looking to take on an early-stage tech startup, and we ended up being funded by a couple VC firms from Texas. I'm not sure that the distance is what led to our demise, but I can guarantee that it didn't help.  If nothing else, the amount of money we blew on airfare and hotel rooms would have kept our lights on for another couple months.

Continue reading "Columbus: Can we become a tech center?"

Spike Code vs. Reference Architecture

architecture illustration
Image via Wikipedia

I just read a post over on Codebetter.com where Jeremy Miller advises us all to not check in a code spike.  When I initially read this, I got a creepy, crawly feeling because the thought of doing any work at all without checking in makes me a little nervous.

As I read Jeremy's post, though, I became more comfortable with Jeremy's reasoning, and I also came to understand what was driving me nuts when I saw the post in the first place.  Not only did Jeremy not really mean "don't check in your code", but I was reading "spike", and thinking "reference architecture."  Let me explain.

The spikes that Jeremy is talking about are explicitly defined as throw-away code in every sense of the word.  There's no expectation that any of this code finds its way into your main source trunk.  You'll also notice that Jeremy ends up suggesting that you actually *do* want to check these spikes in -- just not into your main trunk.

Continue reading "Spike Code vs. Reference Architecture"

BizSpark and Empower for Microsoft Startups

You may be familiar with Microsoft's Empower program for ISV's.  Empower has been around for a few years as a way to help budding ISV startups ship their new Microsoft-based software products, and is widely-regarded as a no-brainer in its target audience.  Until today, if you were contemplating a new software product built with Microsoft development tools, you just couldn't beat Empower.  For an incredibly low price, you get the full MSDN suite of development tools, plus production licenses for OS and back-office products.

Continue reading "BizSpark and Empower for Microsoft Startups"

Could Azure be self-hosted?

LOS ANGELES - OCTOBER 27:  In this photograph ...
Image by Getty Images via Daylife

In response to my Azure reaction, James Bender pointed out that Azure, in its current form, really wouldn't make sense as a self-hosted platform.  Rather than burying this point in a comment, I'm going to talk about it here, because this positioning (by Microsoft) is pivotal, and it's crucial for Microsoft's future.

First, I think James is certainly right about Azure in the form you see today.  Step back from the forest a little, though, and imagine an Azure that's designed specifically for enterprises to deploy into their own data centers.  Certainly, you wouldn't have the (nearly) unlimited scaling that Azure promises, and certainly, you would have a much higher start up cost, which mitigates Azure's appeal for startups, but there's no question at all that Microsoft could have made a self-hosted platform that would create a compute fabric in your own data center.

Continue reading "Could Azure be self-hosted?"