Beispiel #1
0
        public List <T> ToEntityList()
        {
            var      data       = this.ExcuteDataTable();
            List <T> entitylist = new List <T>();

            for (int i = 0; i < data.Rows.Count; i++)
            {
                entitylist.Add(DataRowConvert.ToEntity <T>(data.Rows[i]));
            }
            return(entitylist);
        }
Beispiel #2
0
        public T ToEntity()
        {
            var dt = this.ExcuteDataTable();

            if (dt.Rows.Count == 0)
            {
                return(default(T));
            }
            if (dt.Columns.Count == 1)
            {
                return((T)Convert.ChangeType(dt.Rows[0][0], typeof(T)));
            }
            return(DataRowConvert.ToEntity <T>(dt.Rows[0]));
        }
Beispiel #3
0
        public List <T> ToEntityList(CommandType cmdtype)
        {
            DataTable data = new DataTable();

            if (cmdtype == CommandType.StoredProcedure)
            {
                data = this.ExcuteDbProcedure();
                List <T> entitylist = new List <T>();
                for (int i = 0; i < data.Rows.Count; i++)
                {
                    entitylist.Add(DataRowConvert.ToEntity <T>(data.Rows[i]));
                }
                return(entitylist);
            }
            else if (cmdtype == CommandType.Text)
            {
                return(this.ToEntityList());
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// 根据主键查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public T QueryEntityByKey(string keyValue)
        {
            var key = (from c in EntityContext <T> .Columns where c.Key select c).FirstOrDefault();

            if (key == null)
            {
                throw new Exception("实体未设置主键");
            }
            this.SqlQuery(
                string.Format("DELETE FROM {0} WHERE {1}", EntityContext <T> .TableName,
                              string.Format("{0}=@{0}", key.ColumnName)),
                new DbParameter[] { this.GetDbParameter(key.ColumnName, keyValue) });
            var data = this.ExcuteDataTable();

            if (data.Rows.Count > 0)
            {
                return(DataRowConvert.ToEntity <T>(data.Rows[0]));
            }
            else
            {
                return(default(T));
            }
        }