Ejemplo n.º 1
0
        /// <summary>
        /// 根据ID查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        public T QueryById <T>(int id) where T : BaseModel
        {
            Type   type = typeof(T);
            string sql  = $"{SqlStringCache<T>.GetQuerySql()}where id={id}";

            return(Execute(sql, i =>
            {
                SqlDataReader reader = i.ExecuteReader();
                if (reader.Read())
                {
                    return GetDate <T>(reader);
                }
                return null;
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public List <T> QueryAll <T>() where T : BaseModel
        {
            Type   type = typeof(T);
            string sql  = SqlStringCache <T> .GetQuerySql();

            return(Execute(sql, i =>
            {
                List <T> result = new List <T>();
                SqlDataReader reader = i.ExecuteReader();

                while (reader.Read())
                {
                    result.Add(GetDate <T>(reader));
                }
                return result;
            }));
        }