Ejemplo n.º 1
0
        public IDbConnection CreateConnection()
        {
            var setting = AppConfig.Instance.DatabaseSetting;

            var connectionString = AppDbConnectionBuilder.Build(setting);

            var dbType = setting.DatabaseType.ToLower();

            if (dbType == "postgres")
            {
                return(new NpgsqlConnection(connectionString));
            }
            else if (dbType == "sqlserver")
            {
                return(new SqlConnection(connectionString));
            }
            else if (dbType == "sqlserver")
            {
                return(new SqlConnection(connectionString));
            }
            else if (dbType == "mysql")
            {
                return(new MySqlConnection(connectionString));
            }
            else
            {
            }

            return(null);
        }
Ejemplo n.º 2
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            ConnectionString = AppDbConnectionBuilder.Build(Setting);

            var dbType = Setting.DatabaseType.ToLower();

            if (dbType == "postgres")
            {
                optionsBuilder
                .UseLoggerFactory(new MyLoggerFactory())
                .UseNpgsql(ConnectionString);
            }
            else if (dbType == "sqlserver")
            {
                optionsBuilder
                .UseLoggerFactory(new MyLoggerFactory())
                .UseSqlServer(ConnectionString);
            }
            else if (dbType == "mysql")
            {
                optionsBuilder
                .UseLoggerFactory(new MyLoggerFactory())
                .UseMySQL(ConnectionString);
            }
            else
            {
            }
        }