I've adapted Scott Beeler's C# templates to generate VB.Net code instead. I've also added a few extensions (documented in the notes for each template) and tidied the code up a wee bit. The templates currently generate against our entity framework, but there are minimal (documented) changes required to remove or change this. I've left it in, as I assume most people would have similar entity base classes they'd be generating against.
One of the changes I've made is to extract some of the property generated code into subtemplates. This was because the code was duplicated for joined sub classes, and I also think it makes the main template clear and easier to follow. There are three top level templates:
-
NHibernate.VB.cst - this generates your basic NHibernate mapped class in VB for a specified table
-
NHibernate.hbm.cst - this generates the NHibernate map file for a specified table
-
NHibernate.VBEnum.cst - this generates a non-mapped Enum & class for a specified table
I've not yet written a wrapper to control generation for an entire database, as I plan to do this via an XML configuration file, coupled with a tool to generate the file from a database. I've uploaded it now, as I'm likely to have to get more specific to our framework before I get a chance to do this.
Hope someone finds it useful!
Kev