Beispiel #1
0
 /// <summary>
 /// 执行SQL语句或者存储过程 ,返回IEnumerable<T>
 /// </summary>
 /// <typeparam name="T">返回类似</typeparam>
 /// <param name="connKey">连接字符串Key</param>
 /// <param name="commandText">SQL语句或者存储过程名</param>
 /// <param name="commandParameters">SQL语句或者存储过程参数</param>
 /// <param name="commandType">SQL语句类型</param>
 /// <param name="commandTimeout">超时时间</param>
 /// <returns>IEnumerable</returns>
 public IEnumerable <T> ExecuteIEnumerable <T>(string connKey, string commandText, List <IDataParameter> commandParameters = null, CommandType commandType = CommandType.Text, int?commandTimeout = null) where T : class, new()
 {
     using (SqlConnection conn = GetConnByKey(connKey))
     {
         using (IDataReader dr = SQLHelper.ExecuteReader(conn, commandText, commandParameters, commandType, commandTimeout))
         {
             return(DataReaderExtensions.DataReaderToList <T>(dr));
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 执行SQL语句或者存储过程 ,返回IEnumerable<T>
        /// </summary>
        /// <typeparam name="T">返回类似</typeparam>
        /// <param name="trans">语句所在的事务</param>
        /// <param name="commandText">SQL语句或者存储过程名</param>
        /// <param name="commandParameters">SQL语句或者存储过程参数</param>
        /// <param name="commandType">SQL语句类型</param>
        /// <param name="commandTimeout">超时时间</param>
        /// <returns>IEnumerable</returns>
        public IEnumerable <T> ExecuteIEnumerable <T>(IDbTransaction trans, string commandText, List <IDataParameter> commandParameters = null, CommandType commandType = CommandType.Text, int?commandTimeout = null) where T : class, new()
        {
            IDataReader dr = SQLHelper.ExecuteReader(trans, commandText, commandParameters, commandType, commandTimeout);

            return(DataReaderExtensions.DataReaderToList <T>(dr));
        }