static void CreateSchema() { SchemaExport export = new SchemaExport(m_NHConfiguration); export.SetDelimiter(";"); export.SetOutputFile(@"db.sql").Execute(false, false, false); Console.WriteLine("Schema Exported"); }
private SchemaExport CreateSchemaExport(Configuration config) { var result = new SchemaExport(config); if (!string.IsNullOrEmpty(this.delimiter)) result.SetDelimiter(this.delimiter); if (!string.IsNullOrEmpty(this.outputFile)) result.SetOutputFile(this.outputFile); return result; }
// GET: /Admin/ public ActionResult Index() { var se = new SchemaExport((new Configuration()).Configure()); se.SetDelimiter(";\n"); TextWriter oldOut = Console.Out; var creationSchema = new StringWriter(); Console.SetOut(creationSchema); se.Create(true, false); Console.SetOut(oldOut); ViewBag.SchemaExport = creationSchema.ToString(); return View(); }
public void CriarSchema() { Configuration configuration = SessionFactory.Configuration(); var schemaExport = new SchemaExport(configuration); using (TextWriter stringWriter = new StreamWriter("C:\\exemploNH.sql")) { schemaExport.SetDelimiter(";"); schemaExport.Execute(true, false, false, null, stringWriter); } // Depois de criar as tabelas no MySQL, altere o Storage Engine delas para // InnoDB, assim vc tem suporte a transações (MyISAM, q é o padrão, não suporta). // Vc pode fazer isso por comandos sql: 'ALTER TABLE motoristas ENGINE=InnoDB;' }
/// <summary> /// /// </summary> /// <param name="cfg"></param> /// <param name="outputFileName"></param> /// <param name="script"></param> /// <param name="export"></param> /// <param name="justDrop"></param> public static void ExportSchema(Configuration cfg, string outputFileName, bool script, bool export, bool justDrop) { SchemaExport exporter = new SchemaExport(cfg); //exporter.SetOutputFile(outputFileName); exporter.SetDelimiter(";"); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(outputFileName, false, Encoding.UTF8)) { Console.SetOut(sw); exporter.Execute(script, export, justDrop); } //exporter.Drop(true, false); == == exporter.Execute(true, false, true, true) //exporter.Create(true, false); == exporter.Execute(true, false, false, true) }
public static void AddNHibernate(this IServiceCollection serviceCollection, string type, string connectionString) { var configuration = Fluently.Configure() .Database(GetDatabaseConfiguration(type, connectionString)) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<AccountMap>()); #if DEBUG configuration = configuration.ExposeConfiguration(config => { var schemaExport = new SchemaExport(config); schemaExport.SetDelimiter(";"); schemaExport.SetOutputFile("schema.sql").Execute(true, false, false); }); #endif var factory = configuration.BuildSessionFactory(); serviceCollection.AddSingleton(factory); serviceCollection.AddScoped<IScopeFactory, ScopeFactory>(); }
/// <summary> /// Executes the task. /// </summary> protected override void ExecuteTask() { Configuration config = new Configuration(); Dictionary<string, string> properties = new Dictionary<string, string>(); properties[NHibernate.Cfg.Environment.ConnectionProvider] = ConnectionProvider; properties[NHibernate.Cfg.Environment.Dialect] = Dialect; properties[NHibernate.Cfg.Environment.ConnectionDriver] = ConnectionDriverClass; properties[NHibernate.Cfg.Environment.ConnectionString] = ConnectionString; config.AddProperties(properties); foreach (string filename in Assemblies.FileNames) { Log(Level.Info, "Adding assembly file {0}", filename); try { Assembly asm = Assembly.LoadFile(filename); config.AddAssembly(asm); } catch (Exception e) { Log(Level.Error, "Error loading assembly {0}: {1}", filename, e); } } SchemaExport se = new SchemaExport(config); if (!IsStringNullOrEmpty(OutputFilename)) { se.SetOutputFile(OutputFilename); } se.SetDelimiter(Delimiter); Log(Level.Debug, "Exporting ddl schema."); se.Execute(OutputToConsole, ExportOnly, DropOnly, FormatNice); if (!IsStringNullOrEmpty(OutputFilename)) { Log(Level.Info, "Successful DDL schema output: {0}", OutputFilename); } }
private static SchemaExport CreateSchemaExport(Configuration cfg) { SchemaExport export = new SchemaExport(cfg); // set the delimiter, but only if it is not the default delimiter if (schemaDelimiter != defaultSchemaDelimiter) { export.SetDelimiter(schemaDelimiter); } return export; }