public SessionSource(FluentConfiguration config) { configuration = config.Configuration; sessionFactory = config.BuildSessionFactory(); dialect = Dialect.GetDialect(configuration.Properties); }
public ISessionFactory InitSessionFactory() { _fluentConfiguration = Fluently.Configure() .Mappings(m => m.FluentMappings.AddFromAssemblyOf<PizzaMap>()) .Database(MsSqlConfiguration.MsSql2008.ShowSql() .IsolationLevel("ReadCommitted") .ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString")) .ShowSql()); return _fluentConfiguration.BuildSessionFactory(); }
/// <summary> /// Create database structure from entities /// </summary> /// <param name="configuration">The configuration.</param> public static void Export(FluentConfiguration configuration) { if (configuration == null) throw new ArgumentNullException("configuration"); Configuration config = null; configuration.ExposeConfiguration(c => config = c); var factory = configuration.BuildSessionFactory(); var export = new SchemaExport(config); export.Execute(false, true, false, factory.OpenSession().Connection, null); }
public ISessionFactory GetSessionFactory() { if (_sessionFactory == null) { _fluentConfiguration = Fluently.Configure().Database(MsSqlConfiguration.MsSql2008.ShowSql().ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString"))) //.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Livro>(new AppAutomappingCfg()))); .Mappings(m => m.FluentMappings.AddFromAssemblyOf<AutorMap>()); _sessionFactory = _fluentConfiguration.BuildSessionFactory(); } return _sessionFactory; }
public static ISessionFactory BuildSessionFactory(FluentConfiguration config) { try { return config.BuildSessionFactory(); } catch (ArgumentException x) { log.FatalException("Error while building session factory", x); throw; } catch (FluentConfigurationException x) { log.FatalException("Error while building session factory", x); throw; } }
/*public ISessionFactory Session { get { session = fluentCfg.BuildSessionFactory(); return session; } }*/ public DatabaseConfiguration() { Encrypter encrypter = new Encrypter("64bit"); string keyword = encrypter.Decrypt("QnV0IHlvdSBkb24ndCByZWFsbHkgbWVhbiBpdA=="); encrypter.SetCrypter("AES"); this.connectionString = encrypter.Decrypt("Sf+ulELX4tNuvsQtUG2EZWPJDPhm8obnrSyEm7F5mtg/eziYSjoIZndeCHk8iZOhvAuMNJBxiiatrRHTt2LVFv/vJNoo8yCHkOO7TwUWv3+l8+Wpis4TSsEvc8zHgEPIucH/OQ2tyYlMboyoFH26dZLZ2Y+Kevfu79VfqLBcKGE=", keyword); fluentCfg = Fluently.Configure().Database(PostgreSQLConfiguration.Standard.ConnectionString(this.connectionString)).Mappings(m => { m.HbmMappings.AddFromAssemblyOf<Users>(); m.HbmMappings.AddFromAssemblyOf<Contacts>(); }); var config = fluentCfg.BuildSessionFactory(); }
private void CreateNHibernateFactory() { string connectionString = ConfigurationManager.ConnectionStrings["SqlExpress"].ConnectionString; Config = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(connectionString)) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Log>()) .ExposeConfiguration( c => c.SetProperty("current_session_context_class", "web")); //create session factory SessionFactory = Config.BuildSessionFactory(); }
public static void Config() { _configuration = Fluently .Configure() .Database(MsSqlConfiguration .MsSql2008 .ConnectionString(x => x.FromConnectionStringWithKey("local"))) .Mappings(config => config.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())); var export = new SchemaUpdate(_configuration.BuildConfiguration()); export.Execute(true, true); _sessionFactory = _configuration.BuildSessionFactory(); }
public NHibernateDatabaseTest() { if (Configuration == null) { Configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(ConfigurationManager.ConnectionStrings["Default"].ConnectionString).ShowSql()) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<EmployeeMap>()) .Mappings(m => m.HbmMappings.AddClasses(typeof(CandidateMap))); SessionFactory = Configuration.BuildSessionFactory(); } session = SessionFactory.OpenSession(); }
public static ISessionFactory CreateSessionFactory(string portalServer, string portalDatabase) { FluentNHibernate.Cfg.FluentConfiguration config = Fluently.Configure() .Database(PostgreSQLConfiguration.Standard .ConnectionString(c => c .Host(portalServer) //202.4.229.96 .Port(5432) .Database(portalDatabase) .Username("ofp_admin") .Password("ofp_admin"))) .Mappings(m => m.FluentMappings.AddFromAssemblyOf <IMS.DAL.Maps.Ves.VesselCategoriesMap>()); //.ExposeConfiguration(con => // { // con.SetProperty("adonet.batch_size", "1"); // }) return(config.BuildSessionFactory()); }
public NhibernateModule() { _fluentConfig = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(c => c .FromConnectionStringWithKey("GriffinWiki")) ) .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())); /*m.FluentMappings.Conventions.AddFromAssemblyOf<PrimaryKeyConvention>(); m.FluentMappings.Conventions.Add<PrimaryKeyConvention>(); m.FluentMappings.Conventions.Add<ForeignKeyNameConvention>(); m.FluentMappings.AddFromAssemblyOf<Program>();*/ //_fluentConfig.ExposeConfiguration(x => x.EventListeners.LoadEventListeners = new ILoadEventListener[] {this}); //_fluentConfig.ExposeConfiguration(x => x. = new ILoadEventListener[] { this }); //_fluentConfig.ExposeConfiguration(x => x.SetInterceptor(new SqlStatementInterceptor())); //_fluentConfig.ExposeConfiguration(x=>x.l) _sessionFactory = _fluentConfig.BuildSessionFactory(); }
private static ISessionFactory CreateSessionFactory(Assembly contextAssembly, FluentConfiguration factoryConfig, AutoPersistenceModel autoPersistanceModel = null) { // Create mapping config factoryConfig.Mappings(m => { m.HbmMappings.AddFromAssembly(contextAssembly); m.FluentMappings.AddFromAssembly(contextAssembly); if (autoPersistanceModel != null) { m.AutoMappings.Add(autoPersistanceModel); } }); // Exemple of schemaExport and create // factoryConfig.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)); // Create factory var sessionFactory = factoryConfig.BuildSessionFactory(); return sessionFactory; }
public ISessionFactory GetSessionFactory() { if (_sessionFactory == null) { _fluentConfiguration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ShowSql() .ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString"))) //.ConnectionString(@"Data Source=.\sqlexpress;Initial Catalog=Pizzaria;Integrated Security=True")) //.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Pizza>(new AppAutomappingCfg()))); .Mappings(m => m.FluentMappings.AddFromAssemblyOf<PizzaMap>()); //.Conventions.Setup(GetConventions())); _sessionFactory = _fluentConfiguration.BuildSessionFactory(); //var cfg = Fluently.Configure() // .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Usuario>()) // .Database(MsSqlConfiguration.MsSql2008.ShowSql() // .ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString")) // ); } return _sessionFactory; }
/// <summary> /// Prevents a default instance of the <see cref="NHibernateSession"/> class from being created. /// </summary> private NFluentHibernateSession() { fluentConfiguration = Fluently.Configure().ExposeConfiguration(cfg => cfg.SetProperty(Environment.CurrentSessionContextClass, "managed_web")).Database(MySQLConfiguration.Standard.ConnectionString(m => m.FromConnectionStringWithKey("Connectionstring"))).Mappings(m => m.FluentMappings.AddFromAssemblyOf<NFluentHibernateSession>()); factory = fluentConfiguration.BuildSessionFactory(); }
private static void PopulateDb(FluentConfiguration config) { using (var session = config.BuildSessionFactory().OpenSession()) { using (var tx = session.BeginTransaction()) { PopulateLookups(session); var studentRole = new Role(RoleNames.Student) {Name = "Student"}; var instructorRole = new Role(RoleNames.Instructor) {Name = "Instructor"}; var adminRole = new Role(RoleNames.Administrator) {Name = "Administrator"}; session.SaveOrUpdate(studentRole); session.SaveOrUpdate(instructorRole); session.SaveOrUpdate(adminRole); var user = new User {Identifier = "postit"}; user.Profile = new Profile(user) { FirstName = "Scott", LastName = "Kirkland", Email = "*****@*****.**", ImageUrl = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"] }; user.Roles.Add(studentRole); session.SaveOrUpdate(user); var hermes = new User {Identifier = "hconrad"}; hermes.AssociateProfile(new Profile(hermes) { FirstName = "Hermes", LastName = "Conrad", Email = "*****@*****.**", ImageUrl = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"] }); hermes.Roles.Add(instructorRole); session.SaveOrUpdate(hermes); var farnsworth = new User { Identifier = "hfarnsworth" }; farnsworth.AssociateProfile(new Profile(farnsworth) { FirstName = "Hubert", LastName = "Farnsworth", Email = "*****@*****.**", ImageUrl = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"] }); session.SaveOrUpdate(farnsworth); var instructor = new Instructor { FirstName = "Hubert", LastName = "Farnsworth", Email = "*****@*****.**", Identifier = "hfarnworth", User = farnsworth }; var instructor2 = new Instructor { FirstName = "Hermes", LastName = "Conrad", Email = "*****@*****.**", Identifier = "hconrad", User = hermes }; session.SaveOrUpdate(instructor); session.SaveOrUpdate(instructor2); var etype = new ExperienceType { Name = "Exploration", Icon = "icon-flag" }; session.SaveOrUpdate(etype); session.SaveOrUpdate(new ExperienceType {Name = "Collaboration", Icon = "icon-group"}); var outcome = new Outcome {Name = "Outcome 1", Description = "Some outcome", ImageUrl = string.Empty}; session.SaveOrUpdate(outcome); session.SaveOrUpdate(new Outcome { Name = "Super Skills", Description = "Pretty good skillz", ImageUrl = string.Empty }); var experience = new Experience { Creator = user, ExperienceType = etype, Name = "Sample Experience", Description = "This is a bit of text about exactly what I did in this experience", Start = DateTime.Now, Location = "moab, ut", CoverImageUrl = "https://ucdbadges.blob.core.windows.net/publicimagesdev/e600f3de-a969-45af-b70b-7d2f5285e572" }; experience.AddInstructor(instructor); experience.AddInstructor(instructor2); session.SaveOrUpdate(experience); //Badges var category = new BadgeCategory { Name = "SampleCategory", ImageUrl = "https://ucdbadges.blob.core.windows.net/publicimagesdev/12da4d70-207a-45e5-b6e4-f1b418c1802a" }; session.SaveOrUpdate(category); var badge = new Badge { Approved = true, Category = category, CreatedOn = DateTime.UtcNow, Name = "First Badge", Description = "Really interesting badge for being awesome", Creator = user, ImageUrl = "https://ucdbadges.blob.core.windows.net/publicimagesdev/12da4d70-207a-45e5-b6e4-f1b418c1802a" }; badge.AddCriteria("You need to do a, b, c"); badge.AddCriteria("Also you need to be a human"); session.SaveOrUpdate(badge); tx.Commit(); } } }
/// <summary> Rebuild the SessionFactory with the given NHibernate Configuration. </summary> public static void RebuildSessionFactory(FluentConfiguration cfg) { lock (sessionFactory) { try { sessionFactory = cfg.BuildSessionFactory(); configuration = cfg; } catch (System.Exception ex) { throw new InfrastructureException(ex); } } }
public void Configure(Assembly[] asm) { _cfg = new NHibernate.Cfg.Configuration(); _cfg.Configure(); _cfg.Properties[NHibernate.Cfg.Environment.CollectionTypeFactoryClass] = typeof(Net4CollectionTypeFactory).AssemblyQualifiedName; _config = Fluently.Configure(_cfg); SetupConnection(); SetupMappings(asm); UpdateDbSchema(); //ExportDbSchema(); _sessionFactory = _config.BuildSessionFactory(); }
public void RecreateSessionFactory() { _configuration = GetFluentConfiguration(); _sessionFactory = _configuration.BuildSessionFactory(); }
public static void Load() { _config = Fluently.Configure(); if (Manager.Settings.Driver == Settings.DbDriver.Sqlite) { var dbfile = Path.Combine(Manager.Settings.BasePath, Manager.Settings.SqliteFile); var basepath = Path.GetDirectoryName(dbfile); if (basepath != null && !Directory.Exists(basepath)) { try { Directory.CreateDirectory(basepath); } catch (Exception ex) { Logger.Log(String.Format("Could not create directory {0}: {1}", basepath, ex.Message), Logger.LogType.Error, typeof (SessionFactory)); } } Logger.Log(String.Format("Opening Database {0}", dbfile), Logger.LogType.Info, typeof (SessionFactory)); var sqlcfg = SQLiteConfiguration.Standard.UsingFile(dbfile); //sqlcfg.ShowSql(); //sqlcfg.FormatSql(); _config.Database(sqlcfg); } if (Manager.Settings.Driver == Settings.DbDriver.Mysql) { var sqlcfg = MySQLConfiguration.Standard.ConnectionString( String.Format( "Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};", Manager.Settings.MysqlHost, Manager.Settings.MysqlPort, Manager.Settings.MysqlDatabase, Manager.Settings.MysqlUser, Manager.Settings.MysqlPassword )); sqlcfg.Dialect<MySQL55InnoDBDialect>(); //sqlcfg.ShowSql(); //sqlcfg.FormatSql(); _config.Database(sqlcfg); } _config.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Vehicle>()); _factory = _config.BuildSessionFactory(); #if DEBUG //BuildSchema(); #endif }
/// <summary> /// Initialiser method /// </summary> /// <param name="config">The fluent NHibernate configuration from which to build a session factory</param> /// <param name="storageType">The storage mechanism to use</param> public static void Initialise(FluentConfiguration config, UnitOfWorkStorageType storageType) { Initialise(config.BuildSessionFactory(), storageType); }