Ejemplo n.º 1
0
        public void InitNHib()
        {
            //configure logging
            //if (!log.Logger.Repository.Configured)
            //{
            //    XmlConfigurator.Configure();
            //}

            string configFile = "hibernate.cfg.xml";
            var    connString = Configuration.GetConnectionString("SampleAppDB");


            var conn1 = new NHibConfigOptions()
            {
                ConnectionName   = "DEV3",
                ConnectionString = connString,
                FluentAssemblies = new List <Assembly> {
                    Assembly.GetAssembly(typeof(Department))
                }
            };

            NHibernateConfiguration.Initialize(new List <NHibConfigOptions>()
            {
                conn1
            });
        }
        protected void Application_Start()
        {
            #region MVC

            GlobalConfiguration.Configure(WebApiConfig.Register);

            WebApiFilterConfig.RegisterGlobalFilters(GlobalConfiguration.Configuration.Filters);

            #endregion

            #region Logging

            Environment.SetEnvironmentVariable("APPLICATION_PHYSICAL_PATH", HostingEnvironment.ApplicationPhysicalPath);

            Log.Logger = new LoggerConfiguration().ReadFrom.AppSettings().CreateLogger();

            #endregion

            #region NHibernate

            NHibernateConfiguration.Initialize(typeof(UserMap).Assembly, "Refugee", "web");

            #endregion

            #region Unity

            UnityConfig.Initialize();

            #endregion

            #region Object-Object Mapping

            Mapper.Initialize();

            #endregion

            #region Validators

            ValidatorOptions.CascadeMode = CascadeMode.StopOnFirstFailure;

            #endregion
        }
Ejemplo n.º 3
0
        static void Main()
        {
            NHibernateConfiguration.Initialize(typeof(UserMap).Assembly, "Refugee");

            using (ISession session = NHibernateConfiguration.SessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Console.WriteLine("Database creation started.");

                    try
                    {
                        #region Create Schema

                        SchemaExport schemaExport = new SchemaExport(NHibernateConfiguration.Configuration);

                        schemaExport.Execute(true, true, false, session.Connection, null);

                        #endregion

                        #region Import Data

                        session.Save(new User {
                            UserName = "******", Password = "******", RealName = "Alice"
                        });

                        session.Save(new User {
                            UserName = "******", Password = "******", RealName = "Bob"
                        });

                        #endregion

                        transaction.Commit();

                        Console.WriteLine();

                        Console.WriteLine("Database creation finished.");
                    }
                    catch (Exception exception)
                    {
                        transaction.Rollback();

                        Console.WriteLine();

                        Console.WriteLine(exception.Message);

                        Console.WriteLine();

                        if (exception.InnerException != null)
                        {
                            Console.WriteLine(exception.InnerException.Message);
                        }

                        Console.WriteLine();

                        Console.WriteLine("Database creation rollbacked.");
                    }
                }
            }

            Console.WriteLine();

            Console.WriteLine("Press any key to close the program.");

            Console.ReadKey();
        }
Ejemplo n.º 4
0
 private static void InitializeNHibernate()
 {
     NHibernateConfiguration.Initialize();
 }