Sunday, 15 February 2015

.net - Generating Database Schema Script from NHibernate -


I have a NET 2008 MVC application that uses nhibernate. The previous developer did not get to create a database for this project. I'm quite new to vend, and I'm trying to figure out what would be the optimal solution for creating a database script to create a new database using the current mapping. I have gone through many posts on this site, but still do not fully understand how it is to work. Any guidance is appreciated.

Thank you!

"itemprop =" text ">

After assuming that you have the hbm.xml mapping and a valid nhibernate config file, you have a console application The following code can be used to generate SQL schema:

  // hibernate config file configuration cfg = initial configuration load () from new configuration .configure ("hibernate.cfg.xml" ); // assembly in which the hbm.xml mapping are embedded (assuming the product class is in this assembly) cfg.AddAssembly (typeof (product) .Assembly); // This executable folder will be generated in the new SchemaExport (cfg) SQL Schema file. SetOutputFile ("schema.sql") (executed incorrectly, wrong).   

If you have fluent mapping, then it should look more like this:.

  Fluently.Configure () database (MsSqlConfiguration.MsSql2005) .Mappings (M => m.FluentMappings.AddFromAssemblyOf & lt; Product & gt; ()) ExposeConfiguration (config = & gt; ; {New SchemaExport (config) .SetOutputFile ("schema.sql") executed (true, false, false) ;.}) BuildConfiguration ();    

No comments:

Post a Comment