I just wanted to give you folks a quick update on the status of nhibernate's hbm2net that we are rewriting. The version I am posting here is production stable (at least we are using it ;) ), but does still lack some stuff:

  • revise the use of scopes
  • Use Nullables information to do some basic checking in set ops
  • Overwrite Equals and HashCode
  • The part generating the Generics needs to get replaced
  • Supporting List and Set - not only Bag
  • Only regenerate the base class, if there is already a generated class (to protect the user's modifications)
  • Rewrite the EntityWireUp sample

How to install the CodeDOM Renderer for hbm2net

First of all you need to download the complete source code of nhibernate, because you need to compile it from source in order to get CodeDOMRenderer support. This version is compiled against the svn trunk version of June 19th 2006. Download the zip from this post and unzip it into a temp dir. Find the directory trunk\nhibernate\src\NHibernate.Tool.hbm2net inside the nhibernate sourcecode tree and copy the unzipped files there. Then open trunk\nhibernate\src\NHibernate.Everything-2.0.sln using visual studio 2005. That's all we tested. For style, set NHibernate.Tool.hbm2net.Console as startup project and hit Build. It might be the case that the compiler complains about missing AssemblyInfo.cs. That's due to the fact, that they are autogenerated using NAnt. Please go to the NHibernate download page for instructions how to use NAnt to generate the AssemblyInfo.cs. After you did that reopen the sln and hit Build.

How to use the Renderer

CodeDOMRenderer uses hbm2net's built in configuration filesyntax. That means you should craft a config files similar to this one:

XML:
  1. <codegen>
  2.   <generate suffix=".hmb2net" renderer="NHibernate.Tool.hbm2net.CodeDOMRenderer">
  3.     <param name="usePartial">true</param>
  4.     <param name="internalPrefix">_</param>
  5.     <param name="baseclass-prefix">.hmb2net</param>
  6.   </generate>
  7.   <generate renderer="NHibernate.Tool.hbm2net.CodeDOMRenderer">
  8.     <param name="internalPrefix">_</param>
  9.     <param name="generateEmptyPartialClass">true</param>
  10.   </generate>
  11. </codegen>

Then go to the directory that contains you hbm.xml and execute

NHibernate.Tool.hbm2net.Console.exe --config=config.cfg *.hbm.xml

Now you have all the generated classes in the subdirectory "generated".

Please keep in mind that this is beta quality. Use at your own risk.

Download:
Modified NHibernate.Tool.hbm2net

Quick update: There is a binary version and some samples of generated code available now:
hbm2net.CodeDOMRenderer.zip binary version
hbm2net.CodeDOMRenderer.generatedCode.zip

For instructions how to use it, go to: A detailed look at hbm2net’s CodeDOMRenderer.