NHibernate ships with a pretty simple but effective code generator console program named hbm2net. Unfortunatelly it does not use any .NET 2.0 features yet. So I just tried to at least get in partial classes which is a great feature to separate the autogenerated code with any custom changes.
Go to www.hibernate.org and download the nhibernate framework. I strongly recommend though, to get the svn version to get the latest hbm2net version. The one shipped with the stable branch is not that great and this little guide uses the trunk of the svn on June 17, 2006.
What do we need to do? It should be fairly simple to introduce parital classes since we only have to change the filename the class is stored under (from xyz.cs to xyz.base.cs or xyz.hbm2net.cs) and introduce an additional partial at the position of any class modifiers. Hopefully there will be a basic template or any programmatically introduced modifiers. In addition, if there is time, I want to introduce a mechanism that automatically generates the corresponding xyz.cs, if it does not yet exist. So, let's dive in.
Introducing partial
Oh, great. The tool uses Velocity to generate the classes. Great, great, great. Well, that should make it fairly easy to do the modifications. A short runthrough: there is a convert.vm that is used as a template for the class generation. So one solution would be to edit this line:
$clazz.scope $clazz.modifiers $clazz.declarationType \
$clazz.generatedName [...]
to something like this:
$clazz.scope #if(!$clazz.isInterface())partial#end $clazz.modifiers \
$clazz.declarationType $clazz.generatedName [...]
That would be fine. Since I knew where to look, when I found out that the generator uses Velocity, this solution gets 10 points for speed but only 2 points for elegance.
Since "partial" is a class modifier it should be inserted into the template by $clazz.modifiers and not hardcoded. Plus, I have some time on my hand, and I want to learn more about hbm2net. So those 2 points for elegance are more out of curiosity than out of spite. 
Ohoh, I guess this should go on my ever-so-long todo list. Damn this is weird codebase. It is very, very obvious that this was "ported" from Hibernate. Hehehe. Some quite nasty quickhacks to port stuff as well. One class is still called JavaTool.
Oh, well.
The class we have to focus on is ClassMapping. This class is used to resolve everything prefixed with $clazz. in the convert.vm file. (Take a look at VelocityRenderer.render(...) to verify that). Therefore we need the property Modifiers to change the behaviour of $clazz.modifiers. The original one looks like this:
C#:virtual public string Modifiers
{
get
{
if (shouldBeAbstract() &&
(Scope.IndexOf("abstract") == -1)
)
{
return "abstract";
}
else
{
return "";
}
}
}
So we simply create a new class PartialClassMapping that inherits from ClassMapping and overwrites the Property Modifiers with something like:
C#:public override string Modifiers
{
if (Interface)
{
return base.Modifiers;
}
else
{
if (base.Modifiers.Trim() == string.Empty)
{
return "partial";
}
else
{
return "partial " + base.Modifiers;
}
}
}
Be sure to create the right Constructors that simply call base. Download the whole file: PartialClassMapping.cs
Well, now there should be some configuration system. Or a Factory of Strategy Pattern that creates new instances of the appropriate ClassMapping... Hmpf. Well, there are only two files that contains "new ClassMapping" and those are ClassMapping itself and CodeGenerator. So, we introduce a couple of ugly protected virtual methods there to make the CodeGenerator the real keeper of the "configuration" of with classes will be generated.
After some reordering of the Constructors' arguments and refactoring those things worked out - kinda.
Now there is a new command-switch "--net20" that will enable those first tiny .NET 2.0 features. But I guess later there should be Generics involved, when using that switch, etc.
Here are all the downloads for this hack:
PartialClassMapping.cs
ClassMapping.cs
CodeGenerator.cs
And introducing the base class - that's tomorrow. 
Continue here for the second part. Third part.