示例#1
0
        /// <summary>
        ///  根据sql语句、参数执行查询实体对应数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql">sql语句或存储过程</param>
        /// <param name="objParams">参数,例:new {Uname="joyet"}</param>
        /// <returns></returns>
        public virtual List <T> Query <T>(string sql, object objParams)
        {
            List <T> result   = null;
            var      dbEntity = DbBuilder.Query <T>(sql, objParams);

            if (dbEntity == null)
            {
                return(result);
            }
            using (var reader = DbHelper.ExecuteReader(dbEntity.CommandText, dbEntity.DbParams))
            {
                result = DataReaderToEntityList <T>(reader);
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// 根据查询字段、过滤条件Sql、过滤条件参数(参数名和参数值)查询数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queryColumns">要查询字段</param>
        /// <param name="whereSql">过滤条件Sql</param>
        /// <param name="whereParam">过滤条件参数(参数名和参数值),例:new {Uname="joyet",Age = 110}</param>
        /// <returns></returns>
        public virtual List <T> Query <T>(string queryColumns, string whereSql, object whereParam)
        {
            List <T> result   = null;
            var      dbEntity = DbBuilder.Query <T>(queryColumns, whereSql, whereParam);

            if (dbEntity == null)
            {
                return(result);
            }
            using (var reader = DbHelper.ExecuteReader(dbEntity.CommandText, dbEntity.DbParams))
            {
                result = DataReaderToEntityList <T>(reader);
            }
            HandelExecuteDbCallBack(dbEntity.CommandText, dbEntity.DbParams);
            return(result);
        }
示例#3
0
        /// <summary>
        ///根据主键值查询数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual T Query <T>(object id)
        {
            T   result   = default(T);
            var dbEntity = DbBuilder.Query <T>(id);

            if (dbEntity == null)
            {
                return(result);
            }
            using (var reader = DbHelper.ExecuteReader(dbEntity.CommandText, dbEntity.DbParams))
            {
                result = DataReaderToEntity <T>(reader);
            }
            HandelExecuteDbCallBack(dbEntity.CommandText, dbEntity.DbParams);
            return(result);
        }