Make hbm2net generated code look more like .NET 2.0 (Part 3)
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:
- <codegen>
- <generate suffix=".hmb2net" renderer="NHibernate.Tool.hbm2net.CodeDOMRenderer">
- <param name="usePartial">true</param>
- <param name="internalPrefix">_</param>
- <param name="baseclass-prefix">.hmb2net</param>
- </generate>
- <generate renderer="NHibernate.Tool.hbm2net.CodeDOMRenderer">
- <param name="internalPrefix">_</param>
- <param name="generateEmptyPartialClass">true</param>
- </generate>
- </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.

hi,
i have’t got code to execute store procedure using nhibernate 2.0.does it support that sought of execution and if so how …
regards
rohit peshin
Comment on August 25, 2006 @ 07:21:12
Still being worked on? Any chance this will be contributed back into main nhibernate distribution?
Comment on January 5, 2007 @ 02:34:09