ActiveRecord Codesmith Template Updated

I have made a bunch of changes to the ActiveRecord template.  Below is the list of all of the changes. 

Codesmith.zip (18.14 kb)

Changes:

Lookup table Enum and SQL Generation

I have always used enumerations for all of my lookup tables so that I don't have to hard code the lookup ID value in code.  Until now I had generated these by hand but I finally got around to creating the ability to generate the enum and the sql insert statement.  The template expects an integer primary key and a single string based column.  You can have other values in the table but the template will ignore them. 

The SQL script can either be generated with each table in it's own or as a single file.  The template checks to see if the primary key is an identity column and adds the identity_insert tag.  As well the generate script checks to see if the lookup value based on it's primary key is already in the table before trying to add it.  This allows you to run the script multiple times wthout any issues.

Views as ActiveRecord Classes

I added the ability to specify views to be used to generate ActiveRecord classes.  In order to properly generate the class you have to add an extended property to the view called PrimaryKey and specify the column that is the primary key. 

Self-Referencing Tables

I changed the code to look for self-referencing tables and append List to the end of the property.

Ability to not generate Tests

Added a flag to turn off the test code generation.  All the test classes are is a placeholder anyway which so folks didn't want.

Output Structure

I changed the output structure to better organize the code based on the type of database entity (enum, table, view, sql, etc)

PropertyNames structure for use with nHibernate Expression classes

One thing that I have always disliked about using the nHibernate expression classes was that the properties are string values and cannot be compile time checked.  This unfortuantely leads to only finding errors at runtime for the expression queries.  To solve this problem, I implement the suggestions from the Summer of Nhibernate Screencast (http://www.summerofnhibernate.com ) to create a static class for each ActiveRecord class with the name of each property as a string.  I also add a string value for all of the BelongsTo relationships to get return the RelationshipName.ID since you need that in many instances.  As well I created an ActiveRecordTableNames.cs file that has a listing of all of the tables names.

 


SEVDNUG Presentation: ActiveRecord

On Thursday I gave an quick overview of Castle ActiveRecord (http://www.castleproject.org ) as part of the Southeast Valley .NET User Group (http://www.sevdnug.org ).  I thought the presentation went fairly well.  It is hard to really dig into too much code in 15 minutes, so I mainly concentrated on the features of ActiveRecord.  Below is the links to the code that present.  I used nHibernate 1.2 and ActiveRecord RC3. 

AR Code Demo.zip (1.13 mb)

  • ARCodeDemo.DataObjects: ActiveRecord classes
  • ARCodeDemo.Tests: nUnit Tests
  • ARCodeDemo.Web: Sample Web Application. 
  • Dependencies:  the required dll's to reference for the projects.

Database.zip (3.65 mb)

  • Database used for the sample code
  • Need to just re-attached the database
  • App.Config/Web.Config expects a user of SEVDNUG_User with password of SEVDNUG_User

SEVDNUG: Continuous Integration Presentation

Along with the Agile presentation, I also had the pleasure of discussing Continuous Integration.  The talk centered on Cruise Control .Net and Nant.  I enjoyed giving the talk and sharing but unfortunately I didn't do a great job with the demos and they didn't across the way I wanted them to.  I will post some additional information over the next couple of weeks on Nant and CI.  For now, the link below will get you the presentation, the sample application with all of the build scripts, 3 Nant custom task and CCNET Config file that I used for the demo.

CI.zip (390.59 KB)

Included in the ZIP File:

Demo Code

  • default.build - Master build file for the solution
  • common.build - All of the global properties (variables) for the scripts
  • common.build - Project.build - Nant task that can be reused
  • NantSchema.build - nant script to generate nant.xsd that is needed for VS intellisense
  • HelloWorld.DataObject - C# Class Library
  • HelloWorld.SQL - VS 2007 Team System Database Project
  • HelloWorld.SSIS - Has SSIS sample build script
  • HelloWorld.Tests - NUnit Test Project
  • HelloWorld.Web - Web Application Project
  • HelloWorld.WinForm - WinForm Project

Nant Custom Tasks

  • AppSettingsWriter
    • Add/Update AppSettings Nodes in App.config and Web.Config files
    • Very Simple Task. 
    • XMLPoke should take care of what this task does
  • CleanupOldBuildFiles
    • Removes Files/Directories based on either a number of revisions or on a given number of days since creation.
  • TaskSchedulerTasks
    • Add/Updates/Removes Windows Scheduled Task

SEVDNUG: Agile Presentation

Tonight I have the pleasure of presenting on Agile development at the SEVDNUG meeting.  I focused the talk on things that I have learned over the last 4 years of using Agile.  I figured that folks can read the Agile/XP books and get the Agile concept but the books don't discuss things to look out for that can trip you up or how to really convert your project to Agile from a different process.  The presentation started off with a quick overview of Agile and the benefit and then jump into the learnings.  I did include in the backup slides the Agile overview/concept slides since I already had them done from other presentations that I have given.

Agile.zip (464.45 KB)

The presentation is in Powerpoint 2007 format.  If you don't have Office 2007, you can download the Compatibility Pack which will allow you to view/edit/save Office 2007 formatted files