how How can I generate NHibernate mapping files and DB constructs from my domain logic?



I want to implement NHibernate on my domain objects in my project, but I’m not sure how I should go about generating the mapping file, and the database.

I’ve found some questions that kind of touch on this here and here, but I’m starting with my classes already defined, and would like to start from them and work my way down, not the other way around.

Is there any way to do this?

I’m perfectly fine with a multi-stage process, I just want to know what other people have done that was successful for them.

FYI, I want to deploy the database on SQL Server 2005.





About the mapping:
You can create the mapping with the Fluent Mapping like Gary.
When you have a very uncomplicated domain model, you can use Automapping, a convention based mapping feature of FluentNhibernate:

 var sessionFactory = Fluently.Configure()  
     .ConnectionString(c => c  
   .Mappings(m =>  

And that’s all you need.

You can build your database with schemaexport:

var schemaExport = new SchemaExport(configuration);


Facebook Comments

Post a comment