Using NHibernate with Codesmith to generate ORM
Asked Answered
C

3

6

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?

Coyotillo answered 25/3, 2009 at 1:30 Comment(0)
D
4

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.

Disafforest answered 25/3, 2009 at 1:33 Comment(0)
R
1

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.

Rectum answered 25/3, 2009 at 1:38 Comment(4)
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....Disafforest
In your opinion, besides being free, is MyGeneration a better code-gen?Coyotillo
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.Rectum
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.Remodel
O
1

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

Ostracod answered 30/10, 2009 at 17:3 Comment(2)
While I agree that MyGeneration hasn't been updated in ages, in the purpose of full disclosure it's worth noting that you're an active developer on CodeSmith.Utah
Yes, this is true. I've updated most of my posts to indicate that.Ostracod

© 2022 - 2024 — McMap. All rights reserved.