Ejemplo n.º 1
0
 private static DbProviderFactory GetFactoryDirect(DbConnType dbConnType)
 {
     if (dbConnType == DbConnType.MSSQL)                                             //ok
     {
         return(System.Data.SqlClient.SqlClientFactory.Instance);                    //ok
     }
     else if (dbConnType == DbConnType.MYSQL)                                        //ok
     {
         return(GetFactory("MySql.Data.MySqlClient.MySqlClientFactory,MySql.Data")); //ok
     }
     //return GetFactory("MySql.Data.MySqlClient.MySqlClientFactory,MySqlConnector");
     else if (dbConnType == DbConnType.ODPNET) //ok
     {
         return(GetFactory("Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess"));
     }
     else if (dbConnType == DbConnType.ORACLE) //ok
     {
         return(GetFactory("System.Data.OracleClient.OracleClientFactory,System.Data.OracleClient"));
     }
     else if (dbConnType == DbConnType.SQLITE) // ok
     {
         return(GetFactory("System.Data.SQLite.SQLiteFactory, System.Data.SQLite"));
     }
     else if (dbConnType == DbConnType.POSTGRESQL) //ok
     {
         return(GetFactory("Npgsql.NpgsqlFactory,Npgsql"));
     }
     else
     {
         throw new NotSupportedException(dbConnType.ToString());
     }
 }
Ejemplo n.º 2
0
        public static DbProviderFactory GetFactory(DbConnType dbConnType)
        {
            DbProviderFactory result = null;
            string            str    = dbConnType.ToString();

            if (dic.TryGetValue(str, out result))
            {
                return(result);
            }
            result = GetFactoryDirect(dbConnType);
            dic.TryAdd(str, result);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 取类型的字段集合用,连接
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static string GetFieldStr <T>(DbConnType?connType = null, string contact = ",", string prefix = "", bool isExceptField = false, params string[] onlyFields) where T : new()
        {
            Type   t   = typeof(T);
            string key = $"{t.FullName}:{connType?.ToString()}:{contact}:{prefix}:{isExceptField}:{GetFieldsKey(onlyFields)}";
            string ret = "";

            if (tblFields.TryGetValue(key, out ret))
            {
                return(ret);
            }
            ret = GetFieldStrPri(t, connType, contact, prefix, isExceptField, onlyFields);
            if (!string.IsNullOrEmpty(ret))
            {
                tblFields.TryAdd(key, ret);
            }
            return(ret);
        }