コード例 #1
0
ファイル: DbFactory.cs プロジェクト: aooshi/adf
        /// <summary>
        /// 返回一个数据对象
        /// </summary>
        /// <typeparam name="T">数据对象类型</typeparam>
        /// <param name="sqlString">查询语句或过程</param>
        /// <param name="storedProcedure">是否以存储过程执行</param>
        /// <param name="parames">参数列表</param>
        public T GetRow <T>(string sqlString, bool storedProcedure, params IDbDataParameter[] parames) where T : IDbEntity
        {
            using (IDbCommand cmd = CreateCommand(sqlString, storedProcedure, parames))
            {
                using (IDataReader reader = cmd.ExecuteReader())
                {
                    var dbReader = new DbReader(reader);
                    while (reader.Read())
                    {
                        var obj = Activator.CreateInstance <T>();
                        obj.Initialize(dbReader);
                        return(obj);
                    }
                }
            }

            return(default(T));
        }
コード例 #2
0
ファイル: DbFactory.cs プロジェクト: aooshi/adf
        /// <summary>
        /// 返回一个数据对象集
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="sqlString">查询语句</param>
        /// <param name="storedProcedure">是否为存储过程</param>
        /// <param name="parames">参数列表</param>
        public virtual List <T> GetList <T>(string sqlString, bool storedProcedure, params IDbDataParameter[] parames) where T : IDbEntity
        {
            List <T> list = new List <T>(CALLBACK_LIST_CAPACITY);

            using (IDbCommand cmd = CreateCommand(sqlString, storedProcedure, parames))
            {
                using (IDataReader reader = cmd.ExecuteReader())
                {
                    var dbReader = new DbReader(reader);
                    while (reader.Read())
                    {
                        var obj = Activator.CreateInstance <T>();
                        obj.Initialize(dbReader);
                        list.Add(obj);
                    }
                }
            }

            return(list);
        }