Getting SubSonic Setup in Visual Studio - Shawn Oster
Shawn Oster (gravatar)

Getting SubSonic Setup in Visual Studio

I'm a big fan of SubSonic, a ORM/DAL generator slash utility belt of goodness.  Like any tool there is a little configuration and setup you need to do to get everything rolling and while Rob Conery has some great podcasts on doing just this sometimes you just need to remember that one little option vs. wanting to watch a 10 minute podcast again, regardless of how melodic and sweet are the dulcet tones of Mr. Conery's voice.

1. Download and Install SubSonic.

Seems simple but hey, some people need to be told everything :)

2. Create SubSonic DAL as an external tool

Even though SubSonic supports Rails-style auto-gen of your DAL via build providers I like putting my model/DAL in a separate class library and sadly build providers don't play well with class libraries. 

Go to Tools | Externals Tools... click "Add" and make it look like this:

  • That command is your path to sonic.exe
  • If you're working with the MVC Toolkit (and why aren't you?) then change "App_Code\Generated" to "Models\Generated"

3. Create SubSonic DB as an external tool

SubSonic can also version and script your database, very useful for source control and distributing your application.  Same as above but make it look like this:

4. Install SubSonic Schema

I dislike any warnings during a build and one you'll get with SubSonic is it not knowing about the SubSonic config sections.   I did a blog post on how to fix this awhile back but I'm repeating here for the lazy (like myself):

  1. Download SubSonicSchema.xsd (if you right-click to download make sure you save it with an xsd extension)
  2. Put it in C:\Program Files\Microsoft Visual Studio 8.0\Xml\Schemas (adjust accordingly for VS2008)
  3. Edit DotNetConfig.xsd in the same folder and add the following line:

    (I added it right underneath the <xs:schema> opening tag, seems to work.  Also, if you're using Vista you'll need to edit DotNetConfig.xsd in an editor that was started with right-click, Admin, otherwise it'll write a copy of the xsd into the Virutal Store and your changes will never take effect.  Trust me, I learned this the hard way.)

  4. Close Visual Studio if it's running, re-open, ta-da you now have IntelliSense as well as no more annoying "Could not find schema information for..." messages.

5. Install SubSonic code snippets

You add various sections into your web.config to wire up the magic and nothing is more boring than typing the same poop over and over again.  I created some snippets that provide the various bits that you can download here (actually not quite yet since the bits are at work and my VPN is broken right now).

And Bob's your Uncle, you have all the boring schtuff out of the way and now you're ready to start genning ya some code.  If you don't actually know how to start genning your code then I'd suggest watching some of those screencasts I mentioned above.


  • dulcet tones... Hmmmm was that you at my window last night?

  • Ahh, you found me out, though perhaps things take on a little more "dulcetness" after a few homebrews topped off with some single malts.

  • How do you prevent the whole Database being generated into classes? I only want a few tables which I put into an ABP file in the App_Code folder but it doesn't seem to do anything??

  • yo dawg.. this just came in mucho handy!

  • sskalist (gravatar)

    sskalist said
    April 05, 2009

    A minor bug....:
    &lt;xs:include schema[b]l[/b]ocation=&quot;SubSonicSchema.xsd&quot;&gt;&lt;/xs:include&gt;

    should be:
    &lt;xs:include schema[b]L[/b]ocation=&quot;SubSonicSchema.xsd&quot;&gt;&lt;/xs:include&gt;
    &lt;xs:include schema[b]L[/b]ocation=&quot;SubSonicSchema.xsd&quot;/&gt;

Your Information
Mrs. Gravatar (gravatar)

<-- It's a gravatar

your comment