Using NHibernate with Codesmith to Generate ORM

Just started to study NHiberate. It seems rather tedious to write the correct hbm.xml configuration files for each database table.

The question is, can NHibernate read into tables and automatically extract the relationships and the necessary configuration file, as well as the database mapping classes for you? It seems that the programmer still has to do a lot of work on the ground. Then I stumbled upon Codesmith, who got the templates for NHiberate? Does he fill in the gap?

+6
nhibernate codesmith
source share
3 answers

You can use code templates, but it still creates a pain IMHO. The best way is to use Free nHibernate . They have a new auto-matching feature that uses convention configuration. There are no mapping files, it just makes the assumption that you are using similar names, and you can define rules for converting an entity name to a table name.

+4
source share

Code generation can fill this gap very well, I started using CodeSmith, but then they made this payment point, so I switched to MyGeneration . My approach is to attack the database first, generate the codes for the Mapping and gen files, if they do not already exist. It does something very fast, works great for a prototype, and creates test data.

Display files, classes, and databases are often changed manually. In some cases, I tried to get the generated code to work as part of CI, but it turned out to be difficult if you are not disciplined in where you parted with your code changes manually. Partial classes helped, but still the problem is, to put the whole team on one page, nobody likes their code to be rewritten by the tool, even if you can rollback and merge.

+1
source share

I work for CodeSmith ... Please keep in mind that MyGeneration has not been updated forever, which means it also lacks support. CodeSmith fully supports its products and templates. This means that any template errors will also be fixed and checked by Codesmith.

thanks

-Blake Niemyjski

+1
source share

All Articles