Home
» NHibernate
NHibernate Templates
These are templates for CodeSmith to generate classes and mapping files for NHibernate.
They are not complete yet but already produce a good base for working with. More intelligence is needed when creating collection names especially.
Only tables with a single primary key are currently supported other than linking tables which will be recognised and the appropriate many-to-many mapping created. It will also recognise one-to-one and many-to-one relationships and create the appropriate object links in the classes and mapping files. If multiple one-to-one links are found from a table then it is assumed to be a sub-class structure and a base-class and classes that inherit from it are created. Self-joins are also recognised and a parent object plus child collection created.
I will update this page with complete descriptions and instructions plus any updated versions but for now, here are the files:
Update 04 Dec 2005: Scott Beeler of AMD kindly sent some updates that he made to the original templates (many thanks Scott!) which include the following:
- Fixed support for Many-to-Many relationships. These weren't handled correctly.
- Improved naming of properties.
- Added checking for lengths of strings to property set methods.
- Automatic built-in support of the IComparable interface. It supports by-property, bidirectional sorting. This makes using an Nhibernate generated arraylist of objects easy to use as the datasource of something like a gridview where you want to enable bidirectional sorting of any column
The complete download is available in the Downloads area and includes:
NHibernate.cst
Generates C# classes and mapping files for complete database. Calls other templates below.
NHibernate.class.cst
Generates C# class for table
NHibernate.hbm.cst
Generates NHibernate mapping file for table
NHibernate.inc
Include file with functions used by templates above
I cannot guarantee support of these templates but you can contact me at simon@intesoft.net and I will also check the NHibernate project forum.
* Currency rate is approximate and is based on the following rate: £1.00 = $1.90 (9/3/2006).
Copyright © 1998-2006, InteSoft IT Ltd. All Rights Reserved.