public void Export(string file) { Contract.Requires(!string.IsNullOrEmpty(file)); _schema.SetOutputFile(file); _schema.Create(false, false); }
public static void Initial(Configuration config, ILoggerFactory loggerFactory) { //config = config.Configure(); config.Interceptor = new SQLWatcher(loggerFactory); //Enable validation(optional) NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true; //Here, we serialize all decorated classes(but you can also do it class by class) config.Properties["connection.driver_class"] = "NHibernate.Driver.MySqlDataDriver"; config.Properties["connection.connection_string"] = "Database = oa; Data Source = localhost; User Id = root; Password = wjp930514.; Old Guids = True; charset = utf8;"; config.Properties["dialect"] = "NHibernate.Dialect.MySQL5Dialect"; config.Properties["use_sql_comments"] = "true"; config.Properties["command_timeout"] = "30"; config.Properties["adonet.batch_size"] = "100"; config.Properties["order_inserts"] = "true"; config.Properties["order_updates"] = "true"; config.Properties["adonet.batch_versioned_data"] = "true"; config.Properties["show_sql"] = "true"; config.Properties["format_sql"] = "true"; config.Properties["hbm2ddl.auto"] = "update"; config.AddInputStream(NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(Assembly.Load("OA.Domain"))); //HbmSerializer.Default.Serialize(Assembly.Load("OA.Domain"), "Config/hibernate-oa.cfg.xml"); //config.AddXmlFile("Config/hibernate-oa.cfg.xml"); config.SessionFactory().GenerateStatistics(); //用NHibernate.Tool.hbm2ddl.SchemaExport生成表结构到\sql.sql文件当中 SchemaExport export = new SchemaExport(config); export.SetOutputFile(Path.Combine(Directory.GetCurrentDirectory(), "sql.sql")); //设置输出目录 // export.Drop(true, true);//设置生成表结构存在性判断,并删除 export.Create(false, false); //设置是否生成脚本,是否导出来 }
static void Main(string[] args) { log4net.Config.XmlConfigurator.Configure(); var nhConfig = new Configuration().Configure(); var sessionFactory = nhConfig.BuildSessionFactory(); Console.WriteLine("NHibernate configured by App.config!"); //var foo = new NeedLog(); //foo.DoSomething(); var mapper = new ConventionModelMapper(); nhConfig.AddMapping(mapper.CompileMappingFor(new[] { typeof(TestClass) })); var schemaExport = new SchemaExport(nhConfig); //schemaExport.Create(false, true); //Console.WriteLine("已创建表!"); schemaExport.SetOutputFile("db.sql").Execute(false, false, false); Console.WriteLine("生成了SQL文件:{0}", Path.GetFullPath("db.sql")); Console.ReadKey(); }
public void ShouldExportSchema() { schemaExport.SetOutputFile("../../../sqloutput/ddl.sql"); schemaExport.Execute(false, true, false); dropDatabase = true; }
// !! MUITO CUIDADO !! - RECRIA BANCO DE DADOS !! ////////private static void BuildSchema(FluentConfiguration configuration) ////////{ //////// var sessionSource = new SessionSource(configuration); //////// var session = sessionSource.CreateSession(); //////// sessionSource.BuildSchema(session); ////////} //////// ESSE BELEZA private void BuildSchemaToFile(Configuration cfg, string pathFileName) { SchemaExport exp = new SchemaExport(cfg); exp.SetOutputFile(pathFileName); exp.Create(true, false); }
private static void build_schema(Configuration cfg) { SchemaExport s = new SchemaExport(cfg); s.SetOutputFile(Path.Combine(PATH_TO_SCRIPTS, Path.Combine("Up", NAME_OF_SCRIPT))); s.Create(true, false); }
private static void BuildSchema(NHibernate.Cfg.Configuration config) { var export = new SchemaExport(config); export.SetOutputFile(@"c:\output.sql"); export.Execute(true, false, false); }
/// <summary> /// Export generated database schema to DB. /// </summary> protected void SchemaExport(NHibernate.Cfg.Configuration config, ISessionFactory sessionFactory) { if (rebuildDB) { SchemaExport se = new SchemaExport(config); se.SetOutputFile(Path.Combine(appPath, sqlExportDumpFile)); se.Create(true, true); } if (doInserts) { // Use sql insertstatements to populate your DB! ISession sess = null; try { // open a session just for populating the db, it will be closed when done.... sess = sessionFactory.OpenSession(); IDbCommand com = sess.Connection.CreateCommand(); com.CommandText = ReadInsertStatementsToStream(insertsFile).ToString(); com.ExecuteNonQuery(); } catch (ReadInsertStatementsFromFileToStreamException e) { throw e; } catch (Exception e) { throw e; } finally { if (sess != null) { sess.Close(); } } } }
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 Configuration Configure() { var config = Fluently.Configure() .Database( SQLiteConfiguration.Standard.UsingFile("database").ShowSql() //MsSqlConfiguration.MsSql2008.ConnectionString(b => b.FromConnectionStringWithKey("db")) ) .Mappings(m => { var model = AutoMap.Assemblies(new AutomappingConfiguration(), GetAssemblies()); model.Conventions.Add(new SetEnumTypeConvention()); model.Conventions.Add(new UseNewSqlDateTime2TypeConvention()); model.Conventions.Add(new CollectionAccessConvention()); model.Conventions.Add(new SqlTimestampConvention()); model.Conventions.Add(new SetTableNameConvention()); model.Conventions.Add(DefaultLazy.Never()); m.AutoMappings.Add(model); m.AutoMappings.ExportTo("c:\\mapping"); m.FluentMappings.ExportTo("c:\\mapping"); }) .BuildConfiguration(); // Generatre schema before each start var e = new SchemaExport(config); e.SetOutputFile(@"c:\mapping\a.sql"); e.Execute(true, true, false); return(config); }
public void BuildSchema(DbConnection connection = null) { var path = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, $@"schema{connection?.DataSource}.sql"); // this NHibernate tool takes a configuration (with mapping info in) // and exports a database schema from it var schemaExport = new SchemaExport(this._configuration); schemaExport.SetOutputFile(path); schemaExport.Create( useStdOut: true, execute: false); if (connection != null) { schemaExport.Execute( useStdOut: false, execute: true, justDrop: false, connection: connection, exportOutput: null); } else { schemaExport.Execute( useStdOut: false, execute: true, justDrop: false); } }
private void generate_the_schema(Configuration cfg) { var s = new SchemaExport(cfg); s.SetOutputFile(Path.Combine(path_to_sql_scripts_up_folder, name_of_script_to_create)); s.Create(true, false); }
private static void build_schema(Configuration cfg) { SchemaExport schema_export = new SchemaExport(cfg); schema_export.SetOutputFile(@"..\..\..\..\bombali.database\Bombali\Up\0001_CreateTables.sql"); schema_export.Create(true, false); }
private static void ExportSchema(Configuration configuration) { var schemaExport = new SchemaExport(configuration); schemaExport.SetOutputFile(SchemaOutputPath); schemaExport.Execute(false, false, false); }
public void CreateSchema(Configuration configuration, string filenameTarget) { var schemaExport = new SchemaExport(configuration); schemaExport.SetOutputFile(filenameTarget); schemaExport.Create(false, true); }
/// <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); }
public void SaveCreationScript(string targetPath) { Guard.ArgumentIsValidWritableFile(targetPath, "Target Path"); if (_schemaExport != null) { _schemaExport.SetOutputFile(targetPath); } }
public static Configuration ExportSchema(this Configuration cfg) { var schema = new SchemaExport(cfg); //schema.Drop(false, true); schema.SetOutputFile("ParusModel.sql").Create(false, true); return(cfg); }
public void CreateSchema() { var nhConfig = new ConfigurationBuilder().Build(); var schemaExport = new SchemaExport(nhConfig); schemaExport .SetOutputFile(@"db.sql") .Execute(false, false, false); }
public static Configuration DBCreate(this Configuration cfg) { var fileName = "c:\\usr\\create_schema.sql"; var schemaExport = new SchemaExport(cfg); schemaExport.SetOutputFile(fileName); schemaExport.Create(true, true); return(cfg); }
public static void CreateShemaExportFile(string outputfileName, string tenantKey) { var nhConfig = NHHelper.GetNhConfig(tenantKey); var schemaExport = new SchemaExport(nhConfig); schemaExport .SetOutputFile(outputfileName) .Execute(false, false, false); }
private static void BuildSchema(Configuration config) { // This NHibernate tool takes a configuration (with mapping info in) // and exports a database schema from it. var dbSchemaExport = new SchemaExport(config); dbSchemaExport.SetOutputFile("db_creation.sql"); dbSchemaExport.Drop(true, true); dbSchemaExport.Create(false, true); }
static void Main(string[] args) { var cfg = new Configuration() .DataBaseIntegration(db => { db.ConnectionString = ""; db.Dialect <MySQLDialect>(); }); /* Add the mapping we defined: */ var mapper = new ModelMapper(); mapper.AddMapping(typeof(Nuclear.EventSourcing.MySql.RecordedEventMap)); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); cfg.AddMapping(mapping); string outfile = System.Environment.CurrentDirectory + "\\Nuclear.EventSourcing.Schema.mysql"; Console.WriteLine(outfile); StringBuilder data = new StringBuilder(); SchemaExport schema = new SchemaExport(cfg); schema.SetOutputFile(outfile) .Create((a) => { data.AppendLine(a); }, false); System.IO.File.WriteAllText(outfile, data.ToString()); schema.SetOutputFile(outfile).Create(false, false); // schema.Create(true, false); Console.ReadKey(); }
/// <summary> /// Generate the database schema, apply it to the database and save the DDL used into a file. /// </summary> public static void CreateDatabase() { Configuration configuration = new Configuration(); configuration.Configure(); SchemaExport schemaExport = new SchemaExport(configuration); schemaExport.SetOutputFile("SQLite database schema.ddl"); schemaExport.Create(true, true); }
public static void CreateDatabaseSchema(Configuration cfg) { //This will drop your database, be careful here not to run in production, //unless you want to drop your database new SchemaExport(cfg).Drop(true, true); var schemaExport = new SchemaExport(cfg); schemaExport.SetOutputFile("schema.sql"); schemaExport.Create(true, true); }
private void BuildSchema(Configuration cfg) { SchemaExport schemaExport = new SchemaExport(cfg); using (new StreamWriter("create.sql")) { schemaExport.Create(true, true); schemaExport.SetOutputFile("create.txt"); schemaExport.Execute(false, true, false); } }
public void Should_save_schema_to_file() { var cfg = new Configuration(); cfg.Configure(); cfg.AddAssembly(typeof(Product).Assembly); var schemaExport = new SchemaExport(cfg); schemaExport.SetOutputFile("../../GeneratedSchema/schema.sql"); schemaExport.Create(true, true); }
/// <summary> /// Generates the SQL script. /// </summary> public void Generate() { File.Delete(_databaseSchemaFileName); var schemaExport = new SchemaExport(_nhibernateConfigurator.GetConfiguration()); schemaExport.SetOutputFile(_databaseSchemaFileName); schemaExport.Create(true, false); if (!File.Exists(_databaseSchemaFileName) || new FileInfo(_databaseSchemaFileName).Length == 0) { throw new Exception("Error generating database schema"); } }
public FluentInitializer() { // в DebugMode генерим схему БД if (AppSettings.DebugMode) { Configuration cfg = GetConfiguration(); var schemaExport = new SchemaExport(cfg); schemaExport.SetOutputFile(AppDomain.CurrentDomain.BaseDirectory + "\\Admin.sql") .Execute(true, false, false); } }
private void ExposeConfig(Guid customerId, NHibernate.Cfg.Configuration cfg) { if (!Logger.IsEnabled(LogLevel.Trace)) { return; } var schemaExport = new SchemaExport(cfg); schemaExport.SetOutputFile(Utils.MapPath("~/App_Data/Scripts_" + customerId.ToString("n") + ".sql")); schemaExport.Execute(false, false, false); cfg.EventListeners.LoadEventListeners = new ILoadEventListener[] { new OrchardLoadEventListener() }; }