/// <summary> /// Initialize /// </summary> /// <param name="mappings">Dapper entity mappings</param> /// <param name="database">Database type</param> /// <param name="connectionString">Connection string</param> public DapperDatabaseContext(DapperEntityMappings mappings, string database, string connectionString) { Mappings = mappings; Connection = null; Transaction = null; TransactionLevel = 0; databaseType = database; // Create database connection var pathConfig = Application.Ioc.Resolve <PathConfig>(); if (string.Compare(database, "MSSQL", true) == 0) { Connection = new SqlConnection(connectionString); } else if (string.Compare(database, "SQLite", true) == 0) { Connection = new SqliteConnection( connectionString.Replace("{{App_Data}}", pathConfig.AppDataDirectory)); } else if (string.Compare(database, "MySQL", true) == 0) { Connection = new MySqlConnection(connectionString); } else if (string.Compare(database, "PostgreSQL", true) == 0) { Connection = new NpgsqlConnection(connectionString); } else { throw new ArgumentException($"unsupported database type {database}"); } Connection.Open(); }
/// <summary> /// Initialize<br/> /// 初始化<br/> /// </summary> public DapperDatabaseContextFactory( string database, string connectionString, IEnumerable <IDatabaseInitializeHandler> handlers, IEnumerable <IEntityMappingProvider> providers) { Mappings = new DapperEntityMappings(handlers, providers); Database = database; ConnectionString = connectionString; }
/// <summary> /// Initialize<br/> /// 初始化<br/> /// </summary> /// <param name="mappings">Dapper entity mappings</param> /// <param name="database">Database type</param> /// <param name="connectionString">Connection string</param> public DapperDatabaseContext(DapperEntityMappings mappings, string database, string connectionString) { Mappings = mappings; Connection = null; Transaction = null; TransactionLevel = 0; databaseType = database; // Get default command logger CommandLogger = Application.Ioc.Resolve <IDatabaseCommandLogger>(IfUnresolved.ReturnDefault); // Create database connection var pathConfig = Application.Ioc.Resolve <LocalPathConfig>(); if (string.Compare(database, "MSSQL", true, CultureInfo.InvariantCulture) == 0) { Connection = new Wrappers.SqlConnection( new SqlConnection(connectionString), this); } else if (string.Compare(database, "SQLite", true, CultureInfo.InvariantCulture) == 0) { connectionString = connectionString.Replace("{{App_Data}}", pathConfig.AppDataDirectory); Connection = new Wrappers.SqliteConnection( new SqliteConnection(connectionString), this); } else if (string.Compare(database, "MySQL", true, CultureInfo.InvariantCulture) == 0) { Connection = new Wrappers.MySqlConnection( new MySqlConnection(connectionString), this); } else if (string.Compare(database, "PostgreSQL", true, CultureInfo.InvariantCulture) == 0) { Connection = new Wrappers.NpgsqlConnection( new NpgsqlConnection(connectionString), this); } else { throw new ArgumentException($"unsupported database type {database}"); } Connection.Open(); }
/// <summary> /// Initialize /// </summary> /// <param name="database">Database type</param> /// <param name="connectionString">Connection string</param> public DapperDatabaseContextFactory(string database, string connectionString) { Mappings = new DapperEntityMappings(); Database = database; ConnectionString = connectionString; }