Nhibernate does not generate a new Database, however it is possible to generate new DBs by adding the Npgsql reference.
With this we can now execute:
// 1. Connect to server to create database:
const string connStr = "Server=localhost;Port=5432;User Id=postgres;Password=enter;";
// 2. Connect to server to create table:
const string connStr2 = "Server=localhost;Port=5432;User Id=postgres;Password=enter;Database=testDb";
var m_conn = new NpgsqlConnection(connStr); // db connction
var m_conn2 = new NpgsqlConnection(connStr2); // table connection
// creating a database in Postgresql
m_createdb_cmd = new NpgsqlCommand("CREATE DATABASE IF NOT EXISTS \"testDb\" " +
"WITH OWNER = \"postgres\" " +
"ENCODING = 'UTF8' " +
"CONNECTION LIMIT = -1;", m_conn);
// creating a table in Postgresql
m_createtbl_cmd = new NpgsqlCommand
{
CommandText ="CREATE TABLE table1(ID CHAR(256) CONSTRAINT id PRIMARY KEY, Title CHAR)"
};
m_createtbl_cmd.Connection = m_conn2;
// 3.. Make connection and create
// open connection to create DB
m_conn.Open();
m_createdb_cmd.ExecuteNonQuery();
m_conn.Close();
// open connection to create table
m_conn2.Open();
m_createtbl_cmd.ExecuteNonQuery();
m_conn2.Close();