Beispiel #1
0
        public T GetEntity <T>(string connstr, string sql, params IDbDataParameter[] parameters) where T : IDicSerialize, new()
        {
            T         t  = default(T);
            DataTable dt = ExecuteDataTable(connstr, sql, CommandType.Text, parameters);

            if (dt.Rows.Count == 0)
            {
                return(default(T));
            }
            t = DataMapper.GetObjectV2 <T>(dt, dt.Rows[0]);
            return(t);
        }
Beispiel #2
0
        //public T GetEntityV2<T>(System.Linq.Expressions.Expression<Func<T, bool>> exrp, params IDbDataParameter[] parameters) where T : IDicSerialize, new()
        //{
        //    string condition = exrp.Body.ToString().Replace("&&", "and").Replace("||", "or");
        //    string parateter = string.Empty;
        //    if (exrp.Parameters.Count > 0)
        //    {
        //        parateter = exrp.Parameters[0].Name;
        //    }
        //    else
        //        throw new ApplicationException("No Lambda Parameter");

        //    System.Text.StringBuilder sb = new StringBuilder();
        //    sb.AppendFormat(" select * from {0} as {2} where {1}", typeof(T).Name, condition, parateter);
        //    T t = default(T);
        //    using (IDataReader dr = ExecuteReader(sb.ToString(), parameters))
        //    {
        //        if (dr.Read())
        //            t = DataMapper.GetObjectV2<T>(dr);
        //    }
        //    return t;
        //}


        /// <summary>
        /// 查询实体列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List <T> GetEntityList <T>(DataTable dt) where T : IDicSerialize, new()
        {
            List <T> list = new List <T>();

            if (dt.Rows.Count == 0)
            {
                return(new List <T>());
            }
            foreach (DataRow dr in dt.Rows)
            {
                T t = DataMapper.GetObjectV2 <T>(dt, dr);
                list.Add(t);
            }
            return(list);
        }