Ejemplo n.º 1
0
        /// <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();
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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());
        }