using System; using System.Collections.Generic; using System.Linq; using System.Text; using NHibernate; using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; namespace TestApplication { class NHSessionManager { private static ISessionFactory factory; static NHSessionManager() { try { Configuration cfg = new Configuration(); cfg.Configure("NHibernateConfig.xml"); factory = cfg.BuildSessionFactory(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("NHibernate exception stack"); String formatter = "--"; do { System.Diagnostics.Debug.WriteLine(formatter + ex.Message); ex = ex.InnerException; formatter += "--"; } while (ex != null); throw; } } public static void GenerateSchema() { Configuration cfg = new Configuration(); cfg.Configure("NHibernateConfig1.xml"); new SchemaExport(cfg).Create(false, true); } public static ISession GetSession() { return factory.OpenSession(); } } }