Just started learning NHiberate. It seems rather tedious to write proper hbm.xml config files for each database table.
The question is can NHibernate read into tables and automatically retrieve relationships and needed config file as well as database mapper classes for you? It seems that the programmer still has to do a lot of ground work initially. Then I came across Codesmith which got templates for NHiberate? Does it fill the gap?
You can use code templates, but this still creates a pain IMHO. The best way is to use Fluent nHibernate. They have a new auto-mapper feature, that uses configuration by convention. No mapping files, it just makes assumptions that you use similar names and can define rules of how to convert an entity name to a table name.
Code generation can fill that gap really well, I started using CodeSmith, but then they made that a pay item so I moved to MyGeneration. My approach is to attack the DB first, code gen the Mapping files, and gen classes if they don't already exist. That gets something going really quickly, great for a prototype and creating test data.
The mapping files, classes and DB are often then changed by hand. In some instances I've tried getting the code generation to work as part of CI - but it's proven hard to do that, unless you're disciplined about where you part you're hand crafted code changes. Partial classes were a help, but still a prob to get the whole team on the same page, no-one likes to have their code overwritten by a tool, even if you can then rollback and merge.
I work for CodeSmith... Please keep in mind that MyGeneration hasn't been updated in forever which means it lacks support too. CodeSmith fully supports its products and templates. This means any template bugs will also be fixed and verified by Codesmith.
Thanks
-Blake Niemyjski
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With