/// <summary> /// initializes the session for database /// </summary> private static void Init() { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); config.AddFile("db.cfg.xml");//adds all the embedded resources .hbm.xml config.AddFile("models.xml"); sFactory = config.BuildSessionFactory(); }
public static void AddMappingsFromFilesystem(NHibernate.Cfg.Configuration nhConfiguration) { var directory = System.IO.Directory.GetCurrentDirectory(); var hmbFiles = System.IO.Directory.GetFiles(directory, "*.hbm.xml", System.IO.SearchOption.TopDirectoryOnly); foreach (var file in hmbFiles) { nhConfiguration.AddFile(file); } }
public static ISession OpenSession() { var configuration = new NHibernate.Cfg.Configuration(); var configurationPath = HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\hibernate.cfg.xml"); configuration.Configure(configurationPath); var employeeConfigurationFile = HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\Employee.hbm.xml"); configuration.AddFile(employeeConfigurationFile); ISessionFactory sessionFactory = configuration.BuildSessionFactory(); return(sessionFactory.OpenSession()); }