Using Microsoft ASP.NET MVC with DooDads

Published on Dec 23, 2007

I have been using DooDads, a free, open source ORM architecture for a while now. I like that I can easily use it with any database structure, not matter how bad it is.

When I come across such designs DooDads is the tool that allows me to create a layer of abstraction pretty fast into the application, that will later on allow me to make changes and refactor the database with minimal impact in the upper layers.

I’m also a sucker for the MVC pattern and I downloaded as soon as was available, I have been playing around with it and one of the things I wanted to do was test it’s extensibility using my favorite ORM tool.

Setting things up.

So I fired up VS and create a new MVC application.

I create a db with one table and I call it Movies.

I open MyGeneration and generate the code for the business entity for the table and the Stored Procedures that the object will use.

DooDads Stored Procedures

The Model.

Then I added the code into the Model folder in the solution opened in Visual Studio 2008 and create the concrete class for the Movie object, Doodads generated code use abstract classes.

Model classes in the MVC project

I like to separated the generated code from my implementation using two different folders but you don’t need to do so if you don’t want. I think that is easier to maintain this way.

My next step was to modify the menu to create a Movies item, so I opened the master page and added the following line.

You will need to add the connection string as and appSetting in the web.config for Doodads to pick it up. The key should be dbConnection.

The Controller.

I added a reference to MyGeneration.Doodads.dll and create a new Controller class named MovieController

The code for this class is very simple. I added the using statement for the namespace of my Model classes and I create a custom ViewData object using the new simpler properties.
Declaring the type of the property will give me a strongly typed ViewData in the View.

The View.

I created a folder called Movie under View and inside a Movie page (I made this page of the MVC Content page type to use the same master page).

I added a using for the controllers namespace and set the type of the ViewPage<T> object to my custom viewdata object.

I opened the aspx page and added the following.

And that is all you need.

Final result