CodeSmith Community
Your Code. Your Way. Faster!

NHibernate VB.Net templates


posted by Kev160967
01-24-2008

Downloads: 541
File size: 17.6kB
Views: 2,578
NHibernate VB.Net templates

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:

  1. NHibernate.VB.cst - this generates your basic NHibernate mapped class in VB for a specified table
  2. NHibernate.hbm.cst - this generates the NHibernate map file for a specified table
  3. 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

Comments

leilei642 wrote re: NHibernate VB.Net templates
on 02-22-2008 10:36 PM
It's very nice and clean. Is there a C# version of your template?
Kev160967 wrote re: NHibernate VB.Net templates
on 02-23-2008 2:10 PM
Not at the moment, and in a way it seems like a strange thing to ask given I started from the C# templates. However, I do think the templates are a lot easier to understand and modify now than the originals (though I would say that, wouldn't I!), so maybe it wouldn't be a bad idea. I'm not in a position to do it now, as I've moved things on an awful lot from these templates. I now use a combination of the database and an XML control file to control the code generation. Using extended properties for extra metadata was just too limiting. I'm getting to the point now were you've got more or less the same control over the generated code as you would working with the linq to SQL design environment in VS2008. I've still got some tidying up to do, and I want to add a few more features (like specifying components rather than straight properties) and so on. I've also tidied up the templates a lot more as a result of the work I've done, particularly the HBM ones which are much easier to follow now. Once I've reached a stable point I'll release something new, and then might be a good time to look at C# Kev
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems