/// <summary> /// 创建数据库连接 /// </summary> /// <returns></returns> public static IDbConnection CreateConnection() { IDbConnection conn = DBTypeExtenstions.CreateConnectionByDBType(); if (conn.State == ConnectionState.Closed) { conn.Open(); } return(conn); }
/// <summary> /// 设置数据库类型相关的变量 /// </summary> /// <param name="type">数据库类型</param> private static void InitializeDBType(DBTypeEnum type) { //指定某个具体的数据库类型,仅第一次赋值,其后不用赋值。 if (type == DBTypeEnum.SQLSERVER) { DBTypeExtenstions.SetDBType(type, null); //默认实现为SQLSERVER } else if (type == DBTypeEnum.ORACLE) { DapperExtensions.DapperExtensions.SqlDialect = new DapperExtensions.Sql.OracleSqlDialect(); //DBTypeExtenstions.SetDBType(type, new OracleWfDataProvider()); } else if (type == DBTypeEnum.MYSQL) { DapperExtensions.DapperExtensions.SqlDialect = new DapperExtensions.Sql.MySqlDialect(); //DBTypeExtenstions.SetDBType(type, new MySqlWfDataProvider()); } }
/// <summary> /// 创建类的构造方法 /// </summary> static SessionFactory() { DBTypeExtenstions.SetDBType(DBTypeEnum.SQLSERVER); //DBTypeExtenstions.SetDBType(DBTypeEnum.ORACLE); }