Database() public méthode

Apply database settings
public Database ( Func config ) : FluentConfiguration
config Func Lambda returning database configuration
Résultat FluentConfiguration
Exemple #1
0
        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
        }
        private static void ConnectWithSqlServer2008(FluentConfiguration config)
        {
            config.Database(

                MsSqlConfiguration.MsSql2008
                    .ConnectionString(c => c.FromConnectionStringWithKey("DbConnection"))
                    .ShowSql()
                    ).Cache(c =>
                    c.UseQueryCache().ProviderClass<HashtableCacheProvider>());
        }
 public static ISessionFactory Create(FluentConfiguration fluentConfiguration, DatabaseConfiguration databaseConfiguration) {
     var sessionFactory = fluentConfiguration
         .Database(MsSqlConfiguration.MsSql2005
             .ConnectionString(c => c
                 .Database(databaseConfiguration.DatabaseName)
                 .Server(databaseConfiguration.ServerName)
                 .TrustedConnection())
             .ShowSql())
         .ExposeConfiguration(configuration => {
             if (databaseConfiguration.CreateDatabase) {
                 new SchemaExport(configuration).Create(true, true);
             }
         })
         .BuildSessionFactory();
     return sessionFactory;
 }
        static FluentConfiguration BuildMsSqlDatabase(FluentConfiguration config, string connectString)
        {
            config.Database(MsSqlConfiguration.MsSql2008.ConnectionString(connectString)
               .AdoNetBatchSize(50)
               .IsolationLevel(IsolationLevel.ReadUncommitted)
               .ShowSql()
               .FormatSql()
               );

            return config;
        }
 static FluentConfiguration BuildOracleDatabase(FluentConfiguration config, string connectString)
 {
     config.Database(OracleDataClientConfiguration.Oracle10
              .ConnectionString(connectString)
       .Driver<OracleManagedDataClientDriver>().Provider<DriverConnectionProvider>()
       .Dialect<Oracle10gDialect>()
       .ShowSql().AdoNetBatchSize(50));
     return config;
 }
 private void ConfigureForOracle(FluentConfiguration configuration)
 {
     configuration.Database(OracleClientConfiguration.Oracle10
                                .ConnectionString("Data Source=ORA10.SCORTO.LOCAL2;User Id=gor;Password=gor;")
                                .Dialect(typeof(NHibernate.Dialect.Oracle10gDialect).AssemblyQualifiedName)
                                .Driver(typeof(CustomOracleDriver).AssemblyQualifiedName)
                                .FormatSql()
                                .ShowSql()
                                );
 }
 private void ConfigureForMSSQL(FluentConfiguration configuration)
 {
     configuration.Database(MsSqlConfiguration.MsSql2005
                                .ConnectionString("Data Source=gor-laptop;Initial Catalog=NHibernateSandbox;Persist Security Info=True;User ID=sa;Password=sa123456;Asynchronous Processing=true;MultipleActiveResultSets=True")
                                .Dialect(typeof (NHibernate.Dialect.MsSql2005Dialect).AssemblyQualifiedName)
                                .Driver(typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName)
                                .FormatSql()
                                .ShowSql()
                                );
 }
 private void ConfigureForSQLite(FluentConfiguration configuration)
 {
     configuration.Database( SQLiteConfiguration.Standard
                                 .InMemory()
                                 .FormatSql()
                                 .ShowSql()
         );
 }