About the author

Steven Harmansteven harman :: makes sweet software with computers!

For recent posts and more about me, scroll to the bottom.

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

News

Badges

  • Subtext Project
  • Support Subtext

[Note to Self] SubSonic Requires a Primary Key for Every Table

After stumbling over this a couple of times in the past week I decided to blog-it so I won't forget again.

By convention, SubSonic requires that any tables to be auto-generated into the DAL have a primary key.

#1 sign you're missing a primary key

You have your super-sweet database humming along in it's fully normalized form. You try to generate your DAL with SubSonic but one of your tables isn't being code-gened.

For example, if you have a Customer table then SubSonic should generate the following three classes:

  • Customer
  • CustomerCollection
  • CustomerController

Note: Customer and CustomerCollection will be in the Customer.cs file, and the third class will be in CustomerController.cs.

What others are saying.

# re: [Note to Self] SubSonic Requires a Primary Key for Every Table
Gravatar Andrew
May 09, 2007
I have been looking at SubSonic a lot over the last few weeks. Its a very impressive tool.

I noticed you are also on the SubText development team. Have you had any thoughts about using SubSonic as the DAL in future version. I can see there is MySql support in the roadmap, just wondered what your thoughts were?
# re: [Note to Self] SubSonic Requires a Primary Key for Every Table
Gravatar Steve Harman
May 09, 2007
@Andrew: I don't know that a move to SubSonic is on the official Roadmap yet, but there has certainly been some talk amongst the core devs about doing just that.

One of the biggest advantages of doing so is the multiple database support that we'll get for free! And of course, it should help to really clean up some of the innards by removing a few layers of indirection that make the current DAL a real pain to work with.

Probably the first place you'll start to see SubSonic being used is in the Admin logic. We are moving to an MVP pattern for building the Admin pages and I think that SubSonic could be a really nice fit there.
# re: [Note to Self] SubSonic Requires a Primary Key for Every Table
Gravatar Rob Conery
May 12, 2007
HAH! All you blog are belong to us! :)

You know, I tried to put in as much error handling as I could to catch the PK thing, but is a lack of a PK an exception? I dunno... we went round and round on this...
# re: [Note to Self] SubSonic Requires a Primary Key for Every Table
Gravatar Nathan
Jul 14, 2008
Thanks for the note (even though this post is coming some year later) - I was having trouble compiling the DAL for my fairly complex database, and didn't realize that FK relations which bound to primary keys would not count as PKs to SubSonic. So, added defined primary keys and it worked.

Thanks!
Comments have been closed on this topic.