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 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); } }
private static IDatabase SQLite() { try { var dbFile = AppConfigUtility.AppDirectory + AppConfigUtility.DatabaseName; if (!File.Exists(dbFile)) { throw new DatabaseNotFoundException(); } lock (Locker) { if (_instance != null) { return(_instance); } var connectionString = AppConfigUtility.DatabaseConnString; var connection = new SQLiteConnection(connectionString); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new SqliteDialect()); var sqlGenerator = new SqlGeneratorImpl(config); _instance = new Database(connection, sqlGenerator); } return(_instance); } catch (Exception ex) { LogUtility.Log(LogUtility.LogType.SystemError, MethodBase.GetCurrentMethod().Name, ex.Message); throw new Exception("Erro ao instanciar o banco de dados"); //TODO: put on resource file } }
public static IDatabase GetDatabase(string key, DataBaseType type) { var connectionString = System.Configuration.ConfigurationManager.AppSettings[key]; if (string.IsNullOrEmpty(connectionString)) { throw new ArgumentException("数据库连接字符串不能为空!"); } IDbConnection cnn = null; IDapperExtensionsConfiguration config = null; switch (type) { case DataBaseType.Orcale: config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new OracleDialect()); cnn = new Oracle.ManagedDataAccess.Client.OracleConnection(connectionString); break; case DataBaseType.SqlServer: config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new SqlServerDialect()); cnn = new System.Data.SqlClient.SqlConnection(connectionString); break; default: throw new NotImplementedException("尚未实现对该数据库的支持!"); } var sqlGenerator = new SqlGeneratorImpl(config); return(new Database(cnn, sqlGenerator)); }
public virtual void Setup() { string dbFolder = string.Format(".\\dapperTest"); if (!Directory.Exists(dbFolder)) { Directory.CreateDirectory(dbFolder); } string connectionString = string.Format("server={0};database={1};port={2};Embedded=true", "Embedded", dbFolder, "16080"); var connection = new NxConnection(connectionString); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new NexusDBDialect()); var sqlGenerator = new NexusDBSqlGenerator(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); } }
/// <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);; }
public static IDatabase GetMySqlDatabase(string connectionString) { var factory = new DbConnectionFactory(connectionString, MySqlProvider.Instance); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new MySqlDialect()); return(new Database(factory.Create(), new SqlGeneratorImpl(config))); }
/// <summary> /// Dapper.Ext /// </summary> /// <param name="dbType"></param> /// <param name="dbConnect"></param> /// <returns></returns> public static IDatabase CreateDb(DbType dbType, string dbConnect) { IDbConnection connection = null; IDatabase dbDatabase = null; var config = new DapperExtensionsConfiguration(); switch (dbType) { case DbType.SqlServer: connection = new SqlConnection(dbConnect); config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new SqlServerDialect()); break; case DbType.MySql: connection = new MySqlConnection(dbConnect); config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new MySqlDialect()); break; } var sqlGenerator = new SqlGeneratorImpl(config); dbDatabase = new Database(connection, sqlGenerator); return(dbDatabase); }
/// <summary> /// DapperExtensions 没有实现一对多 /// // 多表联查在这个库里没有提供,多表联查的话可以自己用Dapper的Query<T>(TFirst, TSecond, TResult,...)这个方法来实现 /// </summary> /// <returns></returns> public IEnumerable <TestPersonEntity> TestDapperExtensions() { // Map 文件 TestPersonEntityMapper SqlConnection connection = new SqlConnection(connectionString); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new SqlServerDialect()); // new List<Assembly>() --> Count =0 var sqlGenerator = new SqlGeneratorImpl(config); Db = new Database(connection, sqlGenerator); // 拼接条件 查询 IList <IPredicate> predList = new List <IPredicate>(); predList.Add(Predicates.Field <TestEntity>(p => p.Name, Operator.Like, "A%")); predList.Add(Predicates.Field <TestEntity>(p => p.Id, Operator.Eq, 2)); IPredicateGroup predGroup = Predicates.Group(GroupOperator.And, predList.ToArray()); var ret1 = Db.GetList <TestEntity>(predGroup); var ret2 = Db.GetList <TestPersonEntity>(); connection.Close(); return(ret2); //TestEntity p2 = Db.Get<TestEntity>(1); //return p2.Address; }
private void BuildDatabaseContext() { switch (_dbType) { case DbDialect.SqlServer: var connection = new SqlConnection(_connectionString); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new SqlServerDialect()); var sqlGenerator = new SqlGeneratorImpl(config); DatabaseSession = new Database(connection, sqlGenerator); break; case DbDialect.Oracle: break; case DbDialect.PostgreSql: break; case DbDialect.SqlCe: break; case DbDialect.Sqlite: break; case DbDialect.MySqlDialect: var mysqlConnection = new MySqlConnection(_connectionString); var mysqlConfig = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new MySqlDialect()); var mysqlGenerator = new MySqlGenerator(mysqlConfig); DatabaseSession = new Database(mysqlConnection, mysqlGenerator); break; default: break; } }
private static void InitDB(string connGroupName, IEnumerable <ConnectionItem> list, int state, ref List <Database> db) { string key = connGroupName + "_" + state; if (dict.ContainsKey(key)) { db = dict[key]; } else { var tlist = list.Where(p => p.State == state); try { foreach (var item in tlist) { var cfg = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), item.dBase); var tdb = new Database(item.Connection, new SqlGeneratorImpl(cfg)); db.Add(tdb); } } catch { throw; } if (db.Count > 0) { dict.TryAdd(key, db); } } }
public void GetNextGuid() { var dapperExtensionsConfiguration = new DapperExtensionsConfiguration(); var guid1 = dapperExtensionsConfiguration.GetNextGuid(); var guid2 = dapperExtensionsConfiguration.GetNextGuid(); Assert.NotEqual(guid1, guid2); }
public IDatabase CreateConnection() { var connection = new MySqlConnection(DataSettingsManager.MySqlConnectionString); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new MySqlDialect()); var sqlGenerator = new SqlGeneratorImpl(config); return(new Database(connection, sqlGenerator)); }
public IDatabase GetDatabase() { var connection = new SqlConnection("Integrated Security=False;server=192.168.0.101;database=WALIUJR_SYS;User ID=sa;Password=Cst-88888;Connect Timeout=30"); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new SqlServerDialect()); var sqlGenerator = new SqlGeneratorImpl(config); return(new Database(connection, sqlGenerator)); }
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; }
private void InitDB() { var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new OracleDialect()); var sqlGenerator = new SqlGeneratorImpl(config); connection = new OracleConnection(this.connstr); Db = new Database(connection, sqlGenerator); }
public void SetCaseSensitiveSearch_False_ChangesCaseSensitiveSearchEnabled() { var config = new DapperExtensionsConfiguration(); config.SetCaseSensitiveSearch(false); Assert.IsFalse(config.CaseSensitiveSearchEnabled); }
public DbContextBase(IConfiguration configuration, DbProviderFactory dbProviderFactory, params Type[] mappers) { _configuration = configuration; DbProviderFactory = dbProviderFactory; _configurationContext = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new SqlServerDialect()); }
public DapperHelper(string conn) { var orcalConn = new OracleConnection(conn); var orcaleconfig = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new OracleDialect()); var orcaleGenerator = new SqlGeneratorImpl(orcaleconfig); Connection = new Database(orcalConn, orcaleGenerator); Cmd.Connection = orcalConn; }
static DbTool() { var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>() { typeof(DbTool).GetTypeInfo().Assembly }, new MySqlDialect()); _sqlGenerator = new SqlGeneratorImpl(config); }
/// <summary> /// 构造函数 /// </summary> /// <param name="transaction">事务</param> /// <param name="connection"></param> protected RepositoryBase(IDbTransaction transaction, IDbConnection connection) { Transaction = transaction as DbTransaction; Connection = connection as DbConnection; DapperExtensions.DapperExtensions.SqlDialect = new MySqlDialect(); this.DefaultSort = "ASC"; DapperConfig = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new MySqlDialect()); SqlGenerator = new SqlGeneratorImpl(DapperConfig); }
public void UsingDataBase(Action <IDatabase> action) { var factory = new DbConnectionFactory(connectionString, PostgreSqlProvider.Instance); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new PostgreSqlDialect()); using (IDatabase db = new Database(factory.Create(), new SqlGeneratorImpl(config))) { action(db); } }
private IDatabase CreateDatabase() { var config = new DapperExtensionsConfiguration( _dapperOptionsBuilder.DefaultMapper, _dapperOptionsBuilder.MapperAssemblies, _dapperOptionsBuilder.SqlDialect); var sqlGenerator = new SqlGeneratorImpl(config); return(new Database(_dapperOptionsBuilder.GetDbConnection(), sqlGenerator)); }
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 OracleDataAccess(string connectionName) { string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName].ConnectionString; dbConnection = new OracleConnection(connectionString); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new OracleDialect()); var sqlGenerator = new SqlGeneratorImpl(config); dbExtention = new Database(dbConnection, sqlGenerator); }
public SQLServerDataAccess(string connectionName = "DefaultConnection") { string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName].ConnectionString; dbConnection = new System.Data.SqlClient.SqlConnection(connectionString); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new SqlServerDialect()); var sqlGenerator = new SqlGeneratorImpl(config); dbExtention = new Database(dbConnection, sqlGenerator); }
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 void Test1() { var factory = new DbConnectionFactory(connectionString, MySqlProvider.Instance); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new MySqlDialect()); IDatabase db = new Database(factory.Create(), new SqlGeneratorImpl(config)); var users = db.Select <User>(); //var p = db.Select<Post>(x => x.Id == 1); //var id = db.Insert(new User //{ // Id = 9, // Name = "Lua3" //}); //Console.WriteLine(id); //UsingDbConnectionFactory(db => //{ // //var r = db.Select<User>().ToList(); // //r.Count().ShouldNotBe(0); // var sql =@" // select * from post as p // left join #user as u on u.id = p.ownerid // Order by p.Id"; // var data = db.Query<Post, User, Post>(sql, (p, user) => { p.Owner = user; return p; }); // var post = data.First(); //}); //var factory = new DbConnectionFactory(connectionString, PostgreSqlProvider.Instance); //var config = new DataAccessExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new PostgreSqlDialect()); //IDatabase db2 = new Database(factory.Create(), new SqlGeneratorImpl(config)); //db2.RunInTransaction(() => //{ // //var id = db2.Insert(new User // //{ // // Name = "New1" // //}); // //db2.Insert(new UserEx // //{ // // Id = id, // // NameEx = "New1Ex" // //}); //}); ////var users = db2.GetList<User>(); }
public void ClearCache() { var dapperExtensionsConfiguration = new DapperExtensionsConfiguration(); dapperExtensionsConfiguration.GetMap <TestEntity>(); var propertyInfo = typeof(DapperExtensionsConfiguration).GetField("_classMaps", BindingFlags.Instance | BindingFlags.NonPublic); var cache = (ConcurrentDictionary <Type, IClassMapper>)propertyInfo.GetValue(dapperExtensionsConfiguration); Assert.NotEmpty(cache); dapperExtensionsConfiguration.ClearCache(); cache = (ConcurrentDictionary <Type, IClassMapper>)propertyInfo.GetValue(dapperExtensionsConfiguration); Assert.Empty(cache); }
public DapperInstances BuildImplementor(IEnumerable <Assembly> assemblies, DapperExtensionsConfiguration configuration) { // verify configuration; var classMapperRepository = this.GetInitializedRepository(assemblies, configuration); var sqlGenerator = new PostgresqlGenerator(configuration); configuration.Dialect = new PostgreSqlDialect(); var dapperImplementor = new PostgresqlDapperImplementor(sqlGenerator, classMapperRepository, configuration); var dapperAsyncImplementor = new DapperAsyncImplementor(sqlGenerator, classMapperRepository, configuration); return(new DapperInstances(dapperImplementor, dapperAsyncImplementor)); }
public void Test() { IDapperExtensionsConfiguration conf = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new MySqlDialect()); SqlGeneratorImpl sqlGeneratorImpl = new SqlGeneratorImpl(conf); IFieldPredicate nameFieldPredicate = Predicates.Field <User>(p => p.Name, Operator.Like, "不知道%"); List <ISort> sortList = new List <ISort>(); sortList.Add(Predicates.Sort <User>(u => u.Id)); string selectPagedSql = sqlGeneratorImpl.SelectPaged(new UserMapper(), nameFieldPredicate, sortList, 20, 2, new Dictionary <string, object>()); string res = "SELECT `User`.`Id`, `User`.`Name`, `User`.`Psw`, `User`.`RoleId` FROM `User` WHERE (`User`.`Name` LIKE @Name_0) ORDER BY `User`.`Id` ASC LIMIT @firstResult, @maxResults"; Assert.Equal(selectPagedSql, res); }
public IDatabase GetDatabase() { #if NETSTANDARD2_0 var tableConfigList = JsonConfigurationHelper.GetAppSettings <List <TableConfiguration> >("TableConfigCollection"); var tableConfigEntity = tableConfigList.Where(q => q.Name == _dbName).Select(q => q.ConnectString).FirstOrDefault(); #elif NET45 var tableConfigList = JsonConfigurationHelper.GetAppSettings <TableConfiguration>(); var tableConfigEntity = tableConfigList.Where(q => q.Name == _dbName).Select(q => q.ConnectString).FirstOrDefault(); #endif var connection = new SqlConnection(tableConfigEntity); var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new SqlServerDialect()); var sqlGenerator = new SqlGeneratorImpl(config); return(new Database(connection, sqlGenerator)); }
/// <inheritdoc /> public IDatabase GetDatabase() { if (_database == null) { var dapperOptions = _iocResolver.Resolve <DapperOptionsBuilder>(); var config = new DapperExtensionsConfiguration( dapperOptions.DefaultMapper, dapperOptions.MapperAssemblies, dapperOptions.SqlDialect); var sqlGenerator = new SqlGeneratorImpl(config); _database = new Database(dapperOptions.GetDbConnection(), sqlGenerator); } return(_database); }
public void MySQLBuildTest() { IDapperExtensionsConfiguration conf = new DapperExtensionsConfiguration(typeof(AutoClassMapper <>), new List <Assembly>(), new MySqlDialect()); SqlGeneratorImpl sqlGeneratorImpl = new SqlGeneratorImpl(conf); IFieldPredicate nameFieldPredicate = Predicates.Field <User>(p => p.Name, Operator.Like, "уе%"); string namesql = nameFieldPredicate.GetSql(sqlGeneratorImpl, new Dictionary <string, object>()); Assert.Equal("(`User`.`Name` LIKE @Name_0)", namesql); List <string> valueList = new List <string>() { "1", "2", "3" }; IFieldPredicate nameFieldPredicate2 = Predicates.Field <User>(p => p.Name, Operator.Eq, valueList); string namesql2 = nameFieldPredicate2.GetSql(sqlGeneratorImpl, new Dictionary <string, object>()); Assert.Equal("(`User`.`Name` IN (@Name_0, @Name_1, @Name_2))", namesql2); IBetweenPredicate idFieldPredicate = Predicates.Between <User>(p => p.Name, new BetweenValues { Value1 = 1, Value2 = 10 }, true); string idsql = idFieldPredicate.GetSql(sqlGeneratorImpl, new Dictionary <string, object>()); Assert.Equal("(`User`.`Name` NOT BETWEEN @Name_0 AND @Name_1)", idsql); IPropertyPredicate propertyPredicate = Predicates.Property <User, Role>(u => u.RoleId, Operator.Eq, r => r.Id, true); string propertysql = propertyPredicate.GetSql(sqlGeneratorImpl, new Dictionary <string, object>()); Assert.Equal("(`User`.`RoleId` <> `Role`.`Id`)", propertysql); IExistsPredicate existsPredicate = Predicates.Exists <User>(nameFieldPredicate, true); string existssql = existsPredicate.GetSql(sqlGeneratorImpl, new Dictionary <string, object>()); Assert.Equal("(NOT EXISTS (SELECT 1 FROM `User` WHERE (`User`.`Name` LIKE @Name_0)))", existssql); IList <IPredicate> predList = new List <IPredicate> { nameFieldPredicate, idFieldPredicate }; IPredicateGroup predGroup1 = Predicates.Group(GroupOperator.And, predList.ToArray()); IList <IPredicate> predList2 = new List <IPredicate> { predGroup1, existsPredicate }; IPredicateGroup predGroup2 = Predicates.Group(GroupOperator.Or, predList2.ToArray()); string groupsql = predGroup2.GetSql(sqlGeneratorImpl, new Dictionary <string, object>()); string res = "(((`User`.`Name` LIKE @Name_0) AND (`User`.`Name` NOT BETWEEN @Name_1 AND @Name_2)) OR (NOT EXISTS (SELECT 1 FROM `User` WHERE (`User`.`Name` LIKE @Name_3))))"; Assert.Equal(groupsql, res); }
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 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 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 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);; }