Sunday, August 29, 2010

Using codesmith (5.1) with postgresql for NHibernate

You could say that this post is a modification of ( when you don't have working visual studio integration and/or you want to use codesmith with Postgresql+NHibernate
This is how to use Codesmith professional version 5.1 without visual studio with Postgresql to generate nhibernate templates.

  • First download the Npgsql (version Extract and copy the "Npgsql.dll" and Mono.Security.dll" files to GAC (c:\windows\assembly). Note: This version of npgsql was determined from the dll not found error emitted when your test connection in Codesmith add data source dialog. 
  • Now open "CodeSmith Studio".
  • In the "Schema Explorer" docking window click "Manage Data Sources". Next click "Add". 
    • Name your datasource whatever you want. (hence referred to as "yourdatasource")
    • Select PostgreSQLSchemaProvider.
    • Put in the connection string.
  • Your database connection is setup.  
  • In the "template explorer" click on "create template folder shortcut" icon in the toolbar to create a shortcut to the folder you want to create the Codesmith project in. 
  • right click the newly created "template folder shortcut" and select "New->Codesmith Project".
  • Right click the newly create project and select "Add Output". Browsed and added the following template "C:\Users\Basiee\Documents\CodeSmith\Samples\v5.1\Templates\Frameworks\NHibernate\CSharp". Of course your username / version of codesmith / version of operating system come into play for this address. 
  • Select your "Source Database" to be "yourdatasource" whatever you called it. 
  • Modify your "assembly name" (required ... for your ease) as well as the namespaces (optional) to keep them consistent with the assembly name. 
  • Now right click the project (in Template Explorer) and select "Generate Outputs".