public ActionResult Reset()
        {
            Configuration cfg = new Configuration().Configure();

            new SchemaExport(cfg).Execute(false, true, false);

            ISessionFactory sessionFactory = cfg.BuildSessionFactory();

            using (ISession session = sessionFactory.OpenSession())
            {
                SampleLocations.CreateLocations(session);
                SampleTransportLegs.CreateTransportLegs(session);
                SampleVoyages.CreateVoyages(session);

                session.Flush();
            }

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        private void InitializeNHibernate()
        {
            var cfg = new Configuration();

            cfg.AddProperties(new Dictionary <string, string>
            {
                { Environment.ConnectionDriver, typeof(SQLite20Driver).FullName },
                { Environment.Dialect, typeof(SQLiteDialect).FullName },
                { Environment.ConnectionProvider, typeof(DriverConnectionProvider).FullName },
                { Environment.ConnectionString, "Data Source=:memory:;Version=3;New=True;" },
                {
                    Environment.ProxyFactoryFactoryClass,
                    typeof(ProxyFactoryFactory).AssemblyQualifiedName
                },
                {
                    Environment.CurrentSessionContextClass,
                    typeof(ThreadStaticSessionContext).AssemblyQualifiedName
                },
                { Environment.ReleaseConnections, "on_close" },
                { Environment.Hbm2ddlAuto, "create" },
                { Environment.ShowSql, true.ToString() }
            });
            cfg.AddAssembly("DDDSample.DomainModel.Persistence");

            _sessionFactory = cfg.BuildSessionFactory();
            _ambientContainer.RegisterInstance(_sessionFactory);

            ISession session = _sessionFactory.OpenSession();

            new SchemaExport(cfg).Execute(false, true, false, session.Connection, Console.Out);

            SampleLocations.CreateLocations(session);
            SampleTransportLegs.CreateTransportLegs(session);
            SampleVoyages.CreateVoyages(session);
            SampleCustomers.CreateCustomers(session);
            session.Flush();

            _currentSession = session;

            CurrentSessionContext.Bind(_currentSession);
        }