Code Generating the Repository Pattern with Substage (Subsonic 2.1)


First, I was wrong in my last post and want to correct my statement (will correct in the post soon). You do not have to specify a web root to generate with SubStage. The tool is just not as well documented as I had hoped at first blush. Considering it is an open source project and still in development, that is not a big deal. When you play with projects as they are being developed, you have a few times where you get a bit burned. Wink
 
Now to the fun. In order to generate Repository code, here are the instructions.
 

Add a New Project

Click on the box with the plus in the upper left hand cornder (just below the menu):

Substage - create new project

The only property you have to change here is the name, which I set to UnitWarehouse. Other potential properties to hit are:

TemplateDirectory – if you have your own custom SubSonic templates
EnableTrace – for projects you wish to trace

Add a Connection String

Right click on the connection string node and choose Add Connection String

Substage - Add connection string 1

Now alter the properties to fit your database and name it something other than New Connection String. For mine, I am working with a work project called UnitWarehouse, so my properties are as follows:

ConnectionString: Data Source=(local); Database=UnitWarehouse; Integrated Security=true;
Name: UnitWarehouse

The name is important for a future step.

Add a Provider

Right click on the project and choose Add Provider.

Subsonic - Add new provider

There are tons of properties here, but there are only two that are mandtory for my first pass:
 
Name: UnitWarehouse
TableBaseClass: RepositoryRecord (default is ActiveRecord)
 

Invoke Providers

The next step is to query the provider(s) and find out what they contain. Click on the Invoke Providers button at the upper left (below the menu).

Subsonic - Invoke Providers

This will take a few seconds, but you end up being able to expand the UnitWarehouse provider now, yielding the following:

Subsonic - After Invoke

Generate Code

Before doing this, I would click on the SubStage configuration and place your code where you want. This is done by changing the CodeGenerationPath property. You can go witht he default, which is under the Program Files where Subsonic is installed. I am not fond of this location, however.

Click on the Provider again and then click the Generate Code button. It is the middle above the left pane.

SubSonic - Generate code

This happens fairly quickly.

First Blush

It looks like this will save me some time. I am not seeing the actual repositories created here, but that is not a huge deal, as I can code this out. I also notice there is a stub for foreign keys (and it recognizes them), but it is not there. I will have to look at the roadmap. Overall, however, I am interested in learning more, so I think I may have found a solution. I do not want to return to .NET tiers, as it painted us into a box last time. It may have improved now, but it is Active Record, not repository, so I don’t want to go there.

Before settling in, I will take a look at CodeSmith, just to be sure there are not any good Repository templates. But, thus far, I am willing to continue to implement SubSonic and see where it leads me.

Peace and Grace,
Greg

Advertisements

5 Responses to Code Generating the Repository Pattern with Substage (Subsonic 2.1)

  1. Allen says:

    Thanks for posting this.
    Walking through this, I got a first change opprtunity to configure this new cool interface for Subsonic.
     
    Going in my bookmarks =:)

  2. Allen says:

    –FYI–
    I connected to my MySQL database on my ISP with no problems.
    Just make sure you have the ProviderTypeId set to MySQL under the Provider/General settings.

  3. Gregory says:

    Allen:
     
    It took a bit of time to figure it out, as Rob had the RepositoryRecord bits in his site. It was there, along with the Substage 6 minute video, that helped me get through this. The tool is most useful when you want to output the code rather than have it generated automagically when your site is compiled. And it is the only way to easily use Subsonic with a non-web application.
     
    Peace and Grace,Greg 

  4. Gregory says:

    Allen:
     
    It took a bit of time to figure it out, as Rob had the RepositoryRecord bits in his site. It was there, along with the Substage 6 minute video, that helped me get through this. The tool is most useful when you want to output the code rather than have it generated automagically when your site is compiled. And it is the only way to easily use Subsonic with a non-web application.
     
    Peace and Grace,Greg 

  5. Gregory says:

    Allen:
     
    It took a bit of time to figure it out, as Rob had the RepositoryRecord bits in his site. It was there, along with the Substage 6 minute video, that helped me get through this. The tool is most useful when you want to output the code rather than have it generated automagically when your site is compiled. And it is the only way to easily use Subsonic with a non-web application.
     
    Peace and Grace,Greg 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: