29
votes

Is there a Class Map generator for Fluent NHibernate? I need something like db2hbm but I want it to generate Fluent Class Maps instead of xml mappings.

I am aware of AutoMapping for Fluent but that is not what I want. I want to be able to generate Class Map files from tables in database and push them to my src repository.

4
IMHO if you work in the direction DB->classes you're better off with hbm than fluent-nh. FNH is more intended to infer your schema from your classes.Mauricio Scheffer
I c ur point, but in some apps it turns out that u need to go from db->class model (u do not have control over all decisions made) but at the same time u want to have best of two worlds. U want to generate ur domain model classes from db scheme and have ur persistence layer w/ FNH. Tnx for the comment though.kaptan

4 Answers

60
votes
4
votes

You can do this with Visual NHibernate. Check the Fluent Nhibernate option on the Options screen to create FNH mapping code.

2
votes

LLBLGen Pro is a great tool that can do this and much more. It´s not free, but it´s worth every cent.

1
votes

This is the closest thing I've come across (T4 Templates example to generate Fluent NH mappings): http://www.pnpguidance.net/Post/SampleFluentNHibernateT4TemplatesCodeGenerationLINQToSQL.aspx