コード例 #1
0
        public void Export(string file)
        {
            Contract.Requires(!string.IsNullOrEmpty(file));

            _schema.SetOutputFile(file);
            _schema.Create(false, false);
        }
コード例 #2
0
        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);                                                    //设置是否生成脚本,是否导出来
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: xxfcz/NHCookbook
        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();
        }
コード例 #4
0
ファイル: RepositoryTests.cs プロジェクト: jodyunter/TeamApp
        public void ShouldExportSchema()
        {
            schemaExport.SetOutputFile("../../../sqloutput/ddl.sql");
            schemaExport.Execute(false, true, false);

            dropDatabase = true;
        }
コード例 #5
0
        // !! 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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        private static void BuildSchema(NHibernate.Cfg.Configuration config)
        {
            var export = new SchemaExport(config);

            export.SetOutputFile(@"c:\output.sql");
            export.Execute(true, false, false);
        }
コード例 #8
0
        /// <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();
                          }
                }
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
            }
        }
コード例 #12
0
        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);
        }
コード例 #13
0
ファイル: BombaliService.cs プロジェクト: crazyrex/bombali
        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);
        }
コード例 #14
0
        private static void ExportSchema(Configuration configuration)
        {
            var schemaExport = new SchemaExport(configuration);

            schemaExport.SetOutputFile(SchemaOutputPath);
            schemaExport.Execute(false, false, false);
        }
コード例 #15
0
        public void CreateSchema(Configuration configuration, string filenameTarget)
        {
            var schemaExport = new SchemaExport(configuration);

            schemaExport.SetOutputFile(filenameTarget);
            schemaExport.Create(false, true);
        }
コード例 #16
0
        /// <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);
        }
コード例 #17
0
 public void SaveCreationScript(string targetPath)
 {
     Guard.ArgumentIsValidWritableFile(targetPath, "Target Path");
     if (_schemaExport != null)
     {
         _schemaExport.SetOutputFile(targetPath);
     }
 }
コード例 #18
0
            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);
            }
コード例 #19
0
        public void CreateSchema()
        {
            var nhConfig     = new ConfigurationBuilder().Build();
            var schemaExport = new SchemaExport(nhConfig);

            schemaExport
            .SetOutputFile(@"db.sql")
            .Execute(false, false, false);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
ファイル: NHHelper.cs プロジェクト: wshcdr/multimvc
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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();
        }
コード例 #24
0
        /// <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);
        }
コード例 #26
0
ファイル: DaoTests.cs プロジェクト: kilonet/elfam
        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);
            }
        }
コード例 #27
0
        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);
        }
コード例 #28
0
        /// <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");
            }
        }
コード例 #29
0
        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);
            }
        }
コード例 #30
0
        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() };
        }