views:

1310

answers:

3

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?

+3  A: 

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 nothing...it just makes assumptions that you use simillar names and can define rules of how to convert an entity name to a table name.

JoshBerke
+1  A: 

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.

MrTelly
last project I was on that used code gen'ed turned off the code gene halfway through when we couldn't keep updating the generator fast enough....
JoshBerke
In your opinion, besides being free, is MyGeneration a better code-gen?
Chenster
Don't have enough experience with CodeSmith or others, I find it quirky but good. It's now open source, and the templates are written in C# - all those are pluses.
MrTelly
They both generate code, but CodeSmith is easier to learn and cleaner, but MyGeneration gets the job done just as well, just takes a few to learn the interface and multiple windows.
rball
+1  A: 

Hello,

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

Blake Niemyjski