SubSonic will be your friend

Subsonic claims to have a solution when you have better things to do than worry about Data Access. I, for one, am not very fond of the datalayer in my apps. I rather spend my time on the code instead of stored procedures and SQL queries. So, let’s go ahead and see if SubSonic lives up to its promise.

Let’s open the FrotMachine project from a few posts earlier.
Dowload SubSonic 3.0.0 and add a reference to the SubSonic.Core.dll in the Binaries folder:

reference

Next, create a database. I usually fire up SQL Studio Management Express and create a database by typing:

CREATE DATABASE FrotMachine
GO

Oh well, that’s almost too simple to mention.

Anyway, after that I go back to Visual Studio and add a new App.Config item and make sure it looks like this:

appconfig

Let’s create an instance of a Frot right now and see if a table and a record in the database are being made. But wait, we need to add the using statement for Subsonic first:

using SubSonic.Repository;

Now we can add to our Main method:

var f = new Frot();
            f.FrotID = 1;
            f.FrotName = "GUI Goodness";
            f.FrotDescription = "Create a nice GUI with whatever tool";

//this is the SubSonic part:
            var repo = new SimpleRepository("FrotMachine", SimpleRepositoryOptions.RunMigrations);
            repo.Add(f);

Let’s check out the database now:

table

Isn’t that nice.. it worked. SubSonic created a table and a record in my database. Quite good, isn’t it? It sure is a lot easier than NHibernate. And twice as cool at that.

This may be a trivial example. I’m sure I’ve got my point accross though.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: