Thursday, October 18, 2007

SubSonic: Empty Generated Classes

I’m just starting to play around with SubSonic, a nifty Rails-like DAL package that handles a lot of the goo for you.  Smart Guy (tm) Steve Harman turned me on to this during a conversation some time ago and I’m just getting around to it.

The problem I ran in to right off the bat was that the wicked cool generation tool was giving me classes from the tables with nothing but using declarations in them.  Completely emtpy classes.  Not helpful.

It took me a bit, but I finally figured out that yes, you do need Primary Keys identified for each table you want to generate code against.  I’d had an ID column created with an identity set, but no primary key defined.  Duh.

I may have missed that in the numerous cool screencasts available on SubSonic’s site.  It’s an easy fix, so now I’m off to finish up a project I’m playing with for my talk at the Ann Arbor Day of .NET.


Anonymous said...

Ahhh Google Alerts :). Look for a fix in the coming release where we add a nice message to the class that "you do indeed need a PK". We debated over this and decided to not crash out. It's caused a lot of confusion to be sure.

Jim Holmes said...

I like that gentle kick in the pants approach, Rob. A simple message in the class is a good way to handle that.

I did later find note of this in the "Conventions" section of your documentation -- but that was after I'd fixed the issue. :)

Anonymous said...

>> it's caused a lot of confusion

Yeah, it has... and it's bitten me a few times. Luckily I always had Rob, Eric Kemp, or Jon Galloway to fall back on and they would graciously point me in the right direction. Hopefully the new error message will clear it up a bit.

Oh, and glad that you're getting around to trying out some of the SubSonic love - now if we could just get our hands on the new framework writing code on the .net platform would really be fun again!

David Savage said...

I think you will find SubSonic to be quite a great platform for RAD.

Unknown said...

I am new to Subsonic and trying to work with version 2.0.3. Unfortunately i have the same problem, too, empty classes.
I tried those primary key stuff but could not solve it. Are there anyone to help?

Tom Wayson said...

I have run into this a couple of times too. Seems I missed the memo that said you need a PK. May seem obvious, but I've got a lot of tables for which I need only read only access (reporting summaries), so it would be nifty if SubSonic could generate classes w/o the CRUD and FetchByID methods when it comes across this.

Anonymous said...

Thank you for adding this post. I was running into the same thing playing around with SubSonic, and couldn't figure out why my classes were empty. Altered my IDENTITY( 1, 1 ) column to be a PK as well, and now I have classes.

Thanks for sharing!

Subscribe (RSS)

The Leadership Journey