protected void Application_Start() { AreaRegistration.RegisterAllAreas(); SecurityConfig.ConfigureGlobal(GlobalConfiguration.Configuration); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); // Register exisitng LMs RegisterExisting(); // Load logging info log4net.Config.XmlConfigurator.Configure(); ISessionManager sessionManager = new NHibernateSessionManager(); sessionManager.Configuration.CurrentSessionContext<WebSessionContext>(); SessionFactory = sessionManager.BuildSessionFactory(); }
private void SaveData(string cfg, IEnumerable<User> users) { var targetSessionManager = new NHibernateSessionManager(cfg); targetSessionManager.CreateDatabase(); using (var targetSession = targetSessionManager.BuildSessionFactory().OpenSession()) { using (var tx = targetSession.BeginTransaction()) { try { IRepository repository = new NHibernateRepository(targetSession); foreach (var user in users) { targetSession.Replicate(user, ReplicationMode.Exception); repository.Save(user); } tx.Commit(); } catch (Exception) { tx.Rollback(); throw; } } targetSession.Close(); } }