Beispiel #1
0
        /// <summary>
        /// 获取数据库连接
        /// </summary>
        /// <param name="dbtype">数据库类型</param>
        /// <param name="ConnectionString">数据库连接字符串</param>
        /// <returns>数据库连接</returns>
        //public static IDbConnection CreateConnection()
        //{
        //    return CreateConnection(Appsettings.GetSection("DbOption").Get<DbOption>());
        //}

        /// <summary>
        /// 获取数据库连接
        /// </summary>
        /// <param name="dbtype">数据库类型</param>
        /// <param name="ConnectionString">数据库连接字符串</param>
        /// <returns>数据库连接</returns>
        public static IDbConnection CreateConnection(DbOption dbOption)
        {
            if (dbOption.DbType.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException("获取数据库连接居然不传数据库类型,你想上天吗?");
            }
            if (dbOption.ConnectionString.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException("获取数据库连接居然不传数据库类型,你想上天吗?");
            }
            Appsettings.GetSection("DbOption").Get <DbOption>();
            return(CreateConnection(dbOption.DbType, dbOption.ConnectionString));
        }