Using Subonic ORM to crearte a simple blog

So a couple of buddies of mine showed me a little nifty application called SubSonic. Its A lite and dare i say cute ORM ( Object relation mapper). The reason i like it is because it has low footprint in the project. And i dont have to do any funky configuration to get it to work.

To run the sample you will need One of the Visual studio 2005 flavors…either express or standard and above will due. You will also require SQL Expression or some other SQL Server editions…like 2000 or 2005.

Sample Code: http://quick-max.com/samples/QBlog.net.zip

  1. Run ASPnet_REGSQL.exe and point to the database you want to work with.
  2. Then run locate the BlogTables.SQL and run it against your Prefered Database
  3. Open Up project folder as a website.
  4. Edit your mainCon connection string to point to your database.

Now we are ready to work. The Subsonic.dll has been included in project for you.
You will notice in the app_code directory that there is a builder.adp file. This file is used by subsonic to specify what table you want it to create Objects for. You may specify all table by
putting a ( * ) as the only entry in the file, or specify a table name per line.

Lets compile the project so that Subsonic builds our objects for us. Once you compile then the objects will show up.

You will notice a couple object where created, three of them being QuickMaxBlog, QuickMaxBlogEntry, and QuickMaxBlogEntryComment.

This is basically all we need to save postings to the database.
So lets take a look at Blog.CS

So i took the little nifty RSS Xml writter from Daniel Bright at CodeProject, I just added a couple blog specific functions.

So as you can see from the code sample above, i did not have to write a snippet of sql to get this to work. So the actually time you have developing time decreases. Its almost like mash up programming. I know I know i’m over simplifying it because this those not have any real business rules ……So lets say hypothetically I wanted to add more functionality to the base object created by subsonic…..well theres a little nifty feature in .Net 2.0 called….PARTIAL CLASSES….WHoooo Hooo…. and so all you have to do is create a partical class and you can inject any method, variable or properties that you might want to use…….

….well i hope you guys check this out its pretty nifty….

Subsonic : http://www.codeplex.com/actionpack
Daniel Bright: http://www.codeproject.com/aspnet/RSSviaXmlTextWriter.asp
Sample Code: http://quick-max.com/samples/QBlog.net.zip

Leave a Reply

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