views:

35

answers:

2

I'm looking for ways to generate the application database full structure based on the NHibernate mapping data. The idea is to give the user an option to supply a database-connection string and then to build their a database with the structure that the application needs.

The database need to independent - it means that it needs to work with any database that are supported by NHibernate.

By full structure I mean that I want to generate also the index fields, and the relationship between tables.

Is their few ways to accomplish this with NHibernate? Is so, what are they?

+3  A: 

You use the SchemaExport class for this purpose. The API is a little odd but it works nonetheless.

HTH,
Kent

Kent Boogaart
+1  A: 

You can generate a full database from your C# classes using FNH automapping - I've been doing it on my project for several months now, and I love it!

It's powerful enough to automatically map a deeply nested object graph, including Lists of objects.

It creates all the relationships for you, but - for SQLite, at least - not the indexes.

See http://wiki.fluentnhibernate.org/Auto_mapping for more info.

See http://fnhsamples.codeplex.com/ for a fully working example, kindly provided by Nikola Malovic.

Tom Bushell