Exemple #1
0
        /// <summary>
        /// 获取自定义的对象列表列表
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="type">返回对象类型</param>
        /// <param name="paras"></param>
        /// <returns></returns>
        public List <object> GetCustomerList(string sql, Type type, params object[] paras)
        {
            Command.CommandText = FormatSqlForParameter(sql);
            Command.CommandType = CommandType.Text;
            Command.Parameters.Clear();
            int i = 0;

            foreach (object obj in paras)
            {
                AddParameter(FormatParameterName("p" + (i++).ToString()), ParameterDirection.Input, obj);
            }

            using (IDataReader reader = Command.ExecuteReader())
            {
                return(FullDataReader.CreateDegFullCustomList(reader, type)(reader));
            }
        }
Exemple #2
0
        /// <summary>
        /// 获取自定义对象列表,自己给定SQL语句
        /// 通过字段名称与属性名称匹配来进行填充(不区分大小写)
        /// </summary>
        /// <typeparam name="T">返回的对象类型</typeparam>
        /// <param name="pageIndex">分页索引,以1开始</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="before">加在SQL语句最前面</param>
        /// <param name="fields">字段列表,以“,”分隔</param>
        /// <param name="from">表名称,比如t_a left join t_b on t_a.id=t_b.id</param>
        /// <param name="where">Where 条件,参数用?代替</param>
        /// <param name="group">Group by 子句</param>
        /// <param name="order">排序方式,不包含"order by"</param>
        /// <param name="paras">条件参数</param>
        /// <returns>List</returns>
        public List <object> GetCustomPagingList(Type type,
                                                 int pageIndex,
                                                 int pageSize,
                                                 string before,
                                                 string fields,
                                                 string from,
                                                 string where,
                                                 string group,
                                                 string order,
                                                 params object[] paras)
        {
            Command.CommandType = CommandType.Text;
            string sql = PrepareCustomSelectPaging(pageIndex, pageSize, fields, from, where, group, order, paras);

            Command.CommandText = string.Format("{0} {1}", before, sql);
            using (IDataReader reader = Command.ExecuteReader())
            {
                return(FullDataReader.CreateDegFullCustomList(reader, type)(reader));
            }
        }