public virtual void Setup() { string connectionString = string.Format("Data Source=.\\dapperTest_{0}.sqlite", Guid.NewGuid()); string[] connectionParts = connectionString.Split(';'); string file = connectionParts .ToDictionary(k => k.Split('=')[0], v => v.Split('=')[1]) .Where(d => d.Key.Equals("Data Source", StringComparison.OrdinalIgnoreCase)) .Select(k => k.Value).Single(); if (File.Exists(file)) { File.Delete(file); } SQLiteConnection connection = new SQLiteConnection(connectionString); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new SqliteDialect()); var sqlGenerator = new SqlGeneratorImpl(config); Db = new Database(connection, sqlGenerator); var files = new List<string> { ReadScriptFile("CreateAnimalTable"), ReadScriptFile("CreateFooTable"), ReadScriptFile("CreateMultikeyTable"), ReadScriptFile("CreatePersonTable"), ReadScriptFile("CreateCarTable") }; foreach (var setupFile in files) { connection.Execute(setupFile); } }
public static IDatabase GetDatabase() { SQLiteConnection connection = new SQLiteConnection(sqliteConnectionString); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new SqliteDialect()); var sqlGenerator = new SqlGeneratorImpl(config); IDatabase Db = new Database(connection, sqlGenerator); return Db; }
public MySqlOperator(DataBaseName databaseName, List<Assembly> mappingAssemblies = null) : base(databaseName) { _mappingAssemblies = mappingAssemblies ?? new List<Assembly>() { Assembly.GetCallingAssembly() }; var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), _mappingAssemblies, new MySqlDialect()); SqlGenerator = new SqlGeneratorImpl(config); }
public virtual void Setup() { var connection = new OracleConnection("Data Source=localhost/xe; User Id=xe; Password=xe;"); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new OracleDialect()); var sqlGenerator = new SqlGeneratorImpl(config); Db = new Database(connection, sqlGenerator); var files = new List<string> { ReadScriptFile("CreateAnimalTable"), ReadScriptFile("CreatePersonTable"), ReadScriptFile("CreateCarTable") }; foreach (var setupFile in files) { connection.Execute(setupFile); } }
public virtual void Setup() { var connection = new MySqlConnection("Server=localhost;Port=3306;Database=dapperTest;uid=root;password=password!"); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new MySqlDialect()); var sqlGenerator = new SqlGeneratorImpl(config); Db = new Database(connection, sqlGenerator); var files = new List<string> { ReadScriptFile("CreateFooTable"), ReadScriptFile("CreateMultikeyTable"), ReadScriptFile("CreatePersonTable"), ReadScriptFile("CreateCarTable"), ReadScriptFile("CreateAnimalTable") }; foreach (var setupFile in files) { connection.Execute(setupFile); } }
public virtual void Setup() { var connection = new SqlConnection("Data Source=.;Initial Catalog=dapperTest;Integrated security=True;"); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new SqlServerDialect()); var sqlGenerator = new SqlGeneratorImpl(config); Db = new Database(connection, sqlGenerator); var files = new List<string> { ReadScriptFile("CreateAnimalTable"), ReadScriptFile("CreateFooTable"), ReadScriptFile("CreateMultikeyTable"), ReadScriptFile("CreatePersonTable"), ReadScriptFile("CreateCarTable") }; foreach (var setupFile in files) { connection.Execute(setupFile); } }
public void getDb(String dbName = null) { SqlDialectBase dialect = null; if (String.IsNullOrEmpty(dbName)) { dbname = ConfigFileTool.SAPGlobalSettings.GetCodeTemplateDb(); } else { dbname = dbName; } if (string.IsNullOrEmpty(dbname)) { throw new Exception("Con't get the db connection"); } netlib = new netlib7(dbname); connection = netlib.CreateConnection(); switch (netlib.ProviderType) { case netlib7.ProviderTypes.Oracle: break; case netlib7.ProviderTypes.SqlServer: dialect = new SqlServerDialect(); break; case netlib7.ProviderTypes.MsAccess: dialect = new SqlCeDialect(); break; case netlib7.ProviderTypes.MySql: dialect = new MySqlDialect(); break; case netlib7.ProviderTypes.PostgreSQL: break; case netlib7.ProviderTypes.OleDB: dialect = new SqlCeDialect(); break; case netlib7.ProviderTypes.SQLite: dialect = new SqliteDialect(); break; case netlib7.ProviderTypes.Unknown: break; default: break; } var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), dialect); var sqlGenerator = new SqlGeneratorImpl(config); Db = new Database(connection, sqlGenerator); }
private void InitDb(String dbName = "") { try { if (!String.IsNullOrEmpty(dbName)) { m_dbname = dbName; } else { m_dbname = ConfigFileTool.SAPGlobalSettings.GetDefaultCodeManagerDb(); } if (string.IsNullOrWhiteSpace(m_dbname)) { throw new Exception("Can't get the dbName"); } m_vdb = new SAPINTDB.netlib7(m_dbname); connection = m_vdb.CreateConnection(); switch (m_vdb.ProviderType) { case netlib7.ProviderTypes.Oracle: break; case netlib7.ProviderTypes.SqlServer: dialect = new SqlServerDialect(); break; case netlib7.ProviderTypes.MsAccess: dialect = new SqlCeDialect(); break; case netlib7.ProviderTypes.MySql: dialect = new MySqlDialect(); break; case netlib7.ProviderTypes.PostgreSQL: break; case netlib7.ProviderTypes.OleDB: dialect = new SqlCeDialect(); break; case netlib7.ProviderTypes.SQLite: dialect = new SqliteDialect(); break; case netlib7.ProviderTypes.Unknown: break; default: break; } var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), dialect); var sqlGenerator = new SqlGeneratorImpl(config); Db = new Database(connection, sqlGenerator); } catch (Exception) { throw; } }
/// <summary> /// 打开映射扩展对象 /// </summary> public void OpenMapExt() { var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new SqlServerDialect()); var sqlGenerator = new SqlGeneratorImpl(config); _iDb = new Database(_conn, sqlGenerator);; }