Generate database schema from NHibernate mapping
12,886
Solution 1
Have you tried using NHibernate's built-in schema generation tool?
var cfg = new NHibernate.Cfg.Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(AnEntityInYourMappingLib).Assembly);
new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Execute(false, true, false, false);
Solution 2
I use this code :
public void CreateDatabaseSchemaFromMappingFiles()
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.Configure();
NHibernate.Tool.hbm2ddl.SchemaExport schema = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg);
schema.Create(false, true);
}
Comments
-
Oleksandr almost 2 years
Is it possible to generate the database schema from the Nhibernate mappings DLL?
My requirements is for MySQL. If so, how do I do that? Are there tools/scripts for this? Open source/freeware tools?
Additionally, can I use these tools to insert/update datasets to the database?