-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
NHibernate 4.x Cookbook - Second Edition
By :
In many cases, you'll want to include building or updating your database in some larger process, such as a build script or installation process. In this recipe, we'll show you how to use this command-line tool to run our hbm2ddl tasks.
Download the latest release of NHibernate Schema Tool from http://nst.codeplex.com/.
To install NHibernate Schema Tool, follow these steps:
C:\Program Files named NHibernateSchemaTool.nst.exe to the newly created folder.C:\Program Files\NHibernateSchemaTool to your PATH environment variable.This recipe works for any RDBMS supported by NHibernate. To use a different system, adjust your connection string and dialect accordingly.
hibernate.cfg.xml.To open the command prompt window quickly, in Visual Studio, right-click on your project, and choose Open Folder in Windows Explorer. Open the bin folder. While holding down Shift, right-click on the Debug folder. Choose Open Command Window Here.
nst /c:hibernate.cfg.xml /a:Eg .Core.dll /o:Create.
We haven't added any HBM mapping files to the Eg.Core project yet, so no tables will be created. In the next chapter, however, we will go into some depth on how these mappings are created.
NHibernate Schema Tool is a command-line wrapper for the hbm2ddl tool. This makes NST ideal for use in build scripts and continuous integration servers.
The /c argument specifies the configuration file. The /a argument specifies the assembly with our classes and mapping embedded resource files. The /o:Create option tells NHibernate to create our database objects. It also supports Update and Delete.
NST has several options, enabling a number of creative uses. NST supports these command-line options:
|
Command-line option |
Description |
|---|---|
|
|
Specifies NHibernate |
|
|
Path to assembly or semicolon-separated list of assemblies containing embedded |
|
|
Path to assembly or semicolon-separated list of assemblies containing persistent classes. |
|
|
Directory or directories containing |
|
|
Generate script, but don't execute. Script is written to the console. |
|
|
Generate script and execute. Script is written to the console. |
|
|
Specifies the |