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.

 


Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

November 21. 2008 04:19 PM