Search code examples
databasenhibernatefluent-nhibernate

Is it possible to create a database using NHibernate?


I am using NHibernate with FluentNHibernate for my DAL. I am also using SchemaExport and SchemaUpdate to create and update my database schema.

My problem is that the schema operations all require the database to exist before they will work. I want to programmatically create my database and update the schema as there may be multiple databases and the creating of the database is not only a once-off operation.

I know I can do this manually by executing a create database command on a connection to the master database, but this feels wrong considering that I otherwise use NHibernate for all my database interactions. As an aside, I use a SQLite inmemory database for my unit tests so any sql I write will then have to know which database I'm using.

Is there any way to get NHibernate to create my database for me?


Solution

  • Have a look at RhinoCommons. Under Rhino.Commons.ForTesting, in UnitOfWorkTestContextDbStrategy.cs, Ayende has done some routine there that creates databases.