Tuesday, 17 March 2009

Generating SQL from the NHibernate mapping file

I spent 10 minutes searching for a simple program that would dump out the SQL that NHibernate generates from a mapping file if requested. In the end I just wrote my own. This is the relevant snippet.

                NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
                config.Configure();
                config.AddFile("hbm_mapping.xml");
                
                var export = new NHibernate.Tool.hbm2ddl.SchemaExport(config);
                export.Execute(true, false, false, true);






No comments: