public void DropStructures() { if ((_nhibernateSessionFactory != null) && (_schemaExport != null)) { _schemaExport.Drop(true, true); } }
public void Initialize() { var schema = new SchemaExport(NHConfig.Configuration); schema.Drop(false, true); schema.Create(false, true); }
private static ISessionFactory BuildTestSessionFactory() { var testDatabaseConnectionString = "LocalDB"; var config = DatabaseConfiguration.Configure(testDatabaseConnectionString); /* * Need to comment these out when not needed because session factory can only be created once. * Database schemas need to be created BEFORE NHibernate schema export. * This needs to be run only once. */ /* * var fac = DatabaseConfiguration.BuildSessionFactory(config); * * CreateSchemas(fac);*/ // Drop old database if any, create new schema config.ExposeConfiguration(cfg => { var export = new SchemaExport(cfg); //export.SetOutputFile(@"C:\Temp\vdb.sql"); export.Drop(false, true); export.Create(false, true); }); var fac = DatabaseConfiguration.BuildSessionFactory(config); FinishDatabaseConfig(fac); return(fac); }
private static void DeleteDatabase() { var cfg = DbService.Configure(); var export = new SchemaExport(cfg); export.Drop(false, true); }
private static void CreateSchema(Configuration cfg) { var schemaExport = new SchemaExport(cfg); schemaExport.Drop(false, true); schemaExport.Create(false, true); }
private static void BuildSchema(Configuration configuration) { var schemaExport = new SchemaExport(configuration); schemaExport.Drop(false, true); schemaExport.Create(false, true); }
public void ShouldVerifySameTableTurkish() { //NH-3063 // Turkish have unusual casing rules for the letter 'i'. This test verifies that // code paths executed by the SchemaValidator correctly handles case insensitive // comparisons for this. // Just make sure that we have an int property in the mapped class. This is // the 'i' we rely on for the test. var v = new Version(); Assert.That(v.Id, Is.TypeOf <int>()); var cfg = BuildConfiguration(_version1Resource); var export = new SchemaExport(cfg); export.Create(true, true); try { var validator = new Tool.hbm2ddl.SchemaValidator(cfg); validator.Validate(); } finally { export.Drop(true, true); } }
public void DropDB() { var cfg = DbService.Configure(); var export = new SchemaExport(cfg); export.Drop(true, true); }
public static ISessionFactory CreateSessionGeral() { var _session = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(connectionGeral)) .Mappings(m => m.FluentMappings .Add <UsuarioMap>() .Add <EnderecoMap>() .Add <EstacaoService>() .Add <VeiculoMap>() .Add <EmpresaMap>() ); var session = _session.BuildConfiguration(); if (!initGeral) { var schemaExport = new SchemaExport(session); schemaExport.Execute(false, true, true); schemaExport.Drop(false, true); schemaExport.Create(false, true); var updater = new SchemaUpdate(session); updater.Execute(true, true); var ex = updater.Exceptions; initGeral = true; } return(_session.BuildSessionFactory()); }
public void InitDb() { var session = AppBootstrapper.NHibernate.Factory.OpenStatelessSession(); session.CreateSQLQuery($"create database if not exists `{session.Connection.Database}`;").ExecuteUpdate(); var export = new SchemaExport(Configuration); if (!SwitchUser) { export.Drop(Debug, true); } export.Create(Debug, true); using (var connectionProvider = ConnectionProviderFactory.NewConnectionProvider(Configuration.Properties)) using (var connection = (DbConnection)connectionProvider.GetConnection()) { var cmd = connection.CreateCommand(); var alters = new List <string> { "alter table Offers add fulltext (ProductSynonym);" }; foreach (var alter in alters) { try { if (Log.IsDebugEnabled) { Log.Debug(alter); } cmd.CommandText = alter; cmd.ExecuteNonQuery(); } catch (Exception e) { Log.Warn("Ошибка при обновлении схемы", e); } } } }
static ISessionFactory CreateSessionFactoryForDdl() { FluentConfiguration cfg = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(c => c.FromConnectionStringWithKey("MSSQL2012")) .Dialect <MsSql2012Dialect>() ); cfg.Mappings(m => m .FluentMappings .AddFromAssemblyOf <NHibernateHelper>() ); cfg.ExposeConfiguration(config => { SchemaExport schemaExport = new SchemaExport(config); schemaExport.SetOutputFile(AppDomain.CurrentDomain.BaseDirectory + @"\LedgerLinkDbScript.sql"); schemaExport.Drop(true, true); schemaExport.Create(true, true); schemaExport.Execute(false, false, false); }); SessionFactory = cfg.BuildSessionFactory(); return(SessionFactory); }
private static void BuildSchema(global::NHibernate.Cfg.Configuration config) { var schemaExport = new SchemaExport(config); schemaExport.Drop(false, true); schemaExport.Create(false, true); }
private static void InitMssql() { log4net.Config.XmlConfigurator.Configure(); Console.WriteLine("initializing mssql..."); IPersistenceConfigurer dbCfg = MsSqlConfiguration.MsSql2008 //.ShowSql() .FormatSql() .ConnectionString(c => c.Is(ConfigurationManager.ConnectionStrings["Mssql"].ConnectionString)); var nhCfg = Fluently.Configure() .Database(dbCfg) .Mappings(m => m.AutoMappings .Add( AutoMap.Assembly(typeof(RootFactory).Assembly) .Conventions.Add <CascadeAll>() .Conventions.Add(FluentNHibernate.Conventions.Helpers.DefaultLazy.Never()) // eager loading ).ExportTo("..\\..\\nhmaps")) // to see what is actually going on .ExposeConfiguration(delegate(Configuration cfg) { // preapre schema var schema = new SchemaExport(cfg); schema.Drop(false, true); schema.Create(false, true); }); _sessionFactory = nhCfg.BuildSessionFactory(); }
public void Execute() { var scheme = new SchemaExport(new PersistenceFacility().BuildDatabaseConfiguration()); scheme.Drop(false, true); scheme.Create(false, true); }
/// <summary> /// Creates database schema from scratch. /// </summary> /// <param name="databaseConfiguration">The database configuration.</param> private static void CreateDatabaseSchema(NHibernate.Cfg.Configuration databaseConfiguration) { var schemaExport = new SchemaExport(databaseConfiguration); schemaExport.Drop(false, true); schemaExport.Create(false, true); }
public static ISessionFactory CreateSessionPacote() { var _session = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(connectionPacote)) .Mappings(m => m.FluentMappings .Add <PacoteMap>() .Add <RotaMap>() .Add <LocalizacaoMap>() ); var session = _session.BuildConfiguration(); if (!initPacote) { var schemaExport = new SchemaExport(session); schemaExport.Execute(false, true, true); schemaExport.Drop(false, true); schemaExport.Create(false, true); var updater = new SchemaUpdate(session); updater.Execute(true, true); var ex = updater.Exceptions; initPacote = true; } return(_session.BuildSessionFactory()); }
public static void Configure(string connectionStringKey = null, bool generateTables = false) { if (string.IsNullOrWhiteSpace(connectionStringKey)) { connectionStringKey = System.Configuration.ConfigurationManager.AppSettings["DefaultConnectionStringKey"] ?? "MySQL"; } var cfg = Fluently.Configure() .Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard .ConnectionString(c => c.FromConnectionStringWithKey(connectionStringKey)) .Driver <MySqlDataDriver>() .Dialect <MySQL57SpatialDialect>()) .Mappings(x => x.FluentMappings.AddFromAssemblyOf <MunicipalityMap>()) .BuildConfiguration(); cfg.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg)); if (generateTables) { var exporter = new SchemaExport(cfg); exporter.Drop(false, true); exporter.Create(true, true); } SessionManager.SessionFactory = cfg.BuildSessionFactory(); }
public void First_we_need_a_schema_to_test() { var schemaExport = new SchemaExport(_cfg); schemaExport.Drop(true, true); schemaExport.Create(true, true); try { using (IUnitOfWork work = UnitOfWork.Start()) using (ITransaction transaction = work.BeginTransaction(IsolationLevel.Serializable)) { using (var repository = new NHibernateRepository()) { repository.Save(new TestSaga(_sagaId) { Name = "Joe" }); repository.Save(new TestSaga(CombGuid.Generate()) { Name = "Chris" }); work.Flush(); transaction.Commit(); } } } finally { UnitOfWork.Finish(); } }
/// <summary> /// Generates the database schema. /// </summary> /// <param name="configuration">The configuration.</param> private void GenerateSchema(NHibernate.Cfg.Configuration configuration) { var schemaExport = new SchemaExport(configuration); schemaExport.Drop(false, true); schemaExport.Create(true, true); }
static void ConfigureNHibernate() { var schemaMode = ConfigurationManager.AppSettings["SchemaExportMode"]; var configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(x => x.FromConnectionStringWithKey("MvcStoreDb")) .ProxyFactoryFactory <ProxyFactoryFactory>()) .Mappings(mappings => mappings.FluentMappings.AddFromAssemblyOf <MvcApplication>()) .BuildConfiguration(); _sessionFactory = configuration.BuildSessionFactory(); switch (schemaMode) { case ("CREATE"): var storeInitializer = ServiceLocator.Current.GetInstance <IStoreInitializer>(); var export = new SchemaExport(configuration); export.Drop(false, true); export.Create(false, true); storeInitializer.Initialize(_sessionFactory); break; case ("UPDATE"): new SchemaUpdate(configuration).Execute(false, true); break; } }
/// <summary> /// Drop the database schema, apply it to the database and save the DDL used into a file. /// </summary> /// <param name="schemaOutputFileName"></param> public void DropDatabaseTables(string schemaOutputFileName = null) { SchemaExport schemaExport = new SchemaExport(configuration); schemaExport.SetOutputFile(string.IsNullOrWhiteSpace(schemaOutputFileName) ? "Drop database schema.ddl" : schemaOutputFileName); schemaExport.Drop(true, true); }
private void cmdCriarBancoDeDadosToolStrip_Click(object sender, EventArgs e) { DialogResult rs = MessageBox.Show(this, "Esta operação cria o banco de dados. \n" + "Mas caso o banco de dados já exista ele será apagado.\n\n" + "Deseja realmente executar esta operação?", "Atenção", MessageBoxButtons.OKCancel); if (rs == DialogResult.OK) { createDbSplashScreenManager.ShowWaitForm(); Fluently .Configure() .Database(PostgreSQLConfiguration.PostgreSQL82.ConnectionString(DataBaseManager.CnnStr)) .Mappings(m => m.FluentMappings.AddFromAssemblyOf <Pessoa>()) .ExposeConfiguration(config => { var export = new SchemaExport(config); export.Drop(true, true); export.Create(true, true); }) .BuildSessionFactory(); new DadosIniciais(); } createDbSplashScreenManager.CloseWaitForm(); MessageBox.Show("A aplicação será reiniciada agora.", "Atenção"); Process.GetCurrentProcess().Kill(); }
public void First_we_need_a_schema_to_test() { var schemaExport = new SchemaExport(_cfg); schemaExport.Drop(true, true); schemaExport.Create(true, true); }
public void Test_001_DropSchema() { Configuration cfg = this.TestHelper.GetCfg(AddAssemblies); SchemaExport export = new SchemaExport(cfg); export.Drop(false, true); }
public static void BuildSchema(NHibernate.Cfg.Configuration config, BuildSchemaType buildSchemaType) { switch (buildSchemaType) { case BuildSchemaType.CreateSchema: { var schemaExport = new SchemaExport(config); schemaExport.Create(false, true); break; } case BuildSchemaType.UpdateSchema: { var schemaUpdate = new SchemaUpdate(config); schemaUpdate.Execute(false, true); break; } case BuildSchemaType.DropSchema: { var schemaExport = new SchemaExport(config); schemaExport.Drop(false, true); break; } } }
private static void BuildSchema(Configuration config) { SchemaExport schema = new SchemaExport(config); schema.Drop(false, true); schema.Create(false, true); }
protected void DropSchema_Click(object sender, EventArgs e) { SchemaExport export = new SchemaExport(ExampleApplication.Configuration); export.Drop(false, true); Status.Text = "Schema dropped"; }
public static ISessionFactory CreateSessionFactory(IPersistenceConfigurer persistenceConfigurer = null, NHibernateConfigurationConfigurationOptions configurationOptions = NHibernateConfigurationConfigurationOptions.UpdateDB) { return(Fluently.Configure() .Database(persistenceConfigurer) .Mappings(m => m.FluentMappings.AddFromAssemblyOf <VisitMap>()) //.Mappings(m => m.FluentMappings.AddFromAssemblyOf<WayMap>()) //.Mappings(m => m.FluentMappings.AddFromAssemblyOf<PeriodMap>()) .ExposeConfiguration(cfg => { Config = cfg; switch (configurationOptions) { case NHibernateConfigurationConfigurationOptions.RecreateDB: var export = new SchemaExport(cfg); export.Drop(false, true); export.Create(false, true); break; case NHibernateConfigurationConfigurationOptions.UpdateDB: new SchemaUpdate(cfg).Execute(false, true); break; case NHibernateConfigurationConfigurationOptions.None: break; default: throw new ArgumentOutOfRangeException(nameof(configurationOptions), configurationOptions, "unexpected"); } }) .BuildSessionFactory()); }
public static NhDalFactory Create(string connectionString, bool expose) { var dbConfig = MsSqlConfiguration.MsSql2012 .Dialect <MsSql2012Dialect>() .Driver <SqlClientDriver>() .ConnectionString(connectionString); var cfg = Fluently.Configure() .Mappings(_ => _.FluentMappings .Add <AuthorMapping>() .Add <LikeTargetMapping>() .Add <AuthCookieMapping>() .Add <ThemeMapping>() .Add <CommentMapping>()) .Database(dbConfig) .ExposeConfiguration(_ => { if (expose) { var export = new SchemaExport(_); export.Drop(false, true); export.Create(false, true); } }); var sessionFactory = cfg.BuildSessionFactory(); return(new NhDalFactory(sessionFactory)); }
public static void Configure(string connectionString, bool dropAndCreateTables = false) { var cfg = Fluently.Configure() .Database(FluentNHibernate.Cfg.Db.PostgreSQLConfiguration.Standard .ConnectionString(connectionString) .Driver </*NHibernate.Extensions.NpgSql.NpgSqlDriver*/ NpgsqlDriver>() .Dialect <PostGis20Dialect>()) .Mappings(x => { x.FluentMappings.Add(typeof(GravityVectorMapping <PostGisGeometryType>)); x.FluentMappings.Add(typeof(NormalRouteMapping <PostGisGeometryType>)); x.FluentMappings.Add(typeof(DeviationCellMapping <PostGisGeometryType>)); x.FluentMappings.Add(typeof(NearMissIncidentMapping <PostGisGeometryType>)); } ) .BuildConfiguration() .SetProperty("command_timeout", "-1"); cfg.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg)); if (dropAndCreateTables) { var exporter = new SchemaExport(cfg); exporter.Drop(false, true); exporter.Create(false, true); } SessionManager.SessionFactory = cfg.BuildSessionFactory(); }