Skip to content

Instantly share code, notes, and snippets.

@johnathan-sewell
Created July 28, 2011 21:42
Show Gist options
  • Save johnathan-sewell/1112649 to your computer and use it in GitHub Desktop.
Save johnathan-sewell/1112649 to your computer and use it in GitHub Desktop.
Bare bones NHibernate schema export
using System;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using lexikon.console.domain;
namespace lexikon.console
{
class Program
{
static void Main(string[] args)
{
var config = new Configuration().Configure();
//export schema - drop and recreate table
var schemaExport = new SchemaExport(config);
schemaExport.Create(true, true);
var sessionFactory = config.BuildSessionFactory();
using (ISession session = sessionFactory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
var word = new Word
{
Text = "abracadabra"
};
session.Save(word);
transaction.Commit();
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment