/// <summary> /// 回傳Mapping後的物件列表 /// </summary> /// <param name="dataReader"></param> /// <param name="method"></param> /// <returns></returns> public virtual IList <T> RowsMapping <T>(IDataReader dataReader, ParseToPOCO <T> method) { if (method == null) { throw new Exception("無指定轉型的指派方法可呼叫"); } bool hasData = false; IList <T> list = new List <T>(); do { T obj = default(T); if (hasData = method.Invoke(dataReader, out obj)) { list.Add(obj); } }while (hasData); if (list.Count == 0) { return(null); } else { return(list); } }
/// <summary> /// 執行sqlcommand的ExecuteReader並讓外部帶入委派方法來轉成自訂型別物件 /// </summary> /// <typeparam name="T">外部所要轉的物件類別</typeparam> /// <param name="cmd"></param> /// <param name="parsePOCO_method">轉物件用的委派方法</param> /// <param name="paras"></param> /// <returns></returns> public virtual IList <T> Execute_ReaderToPOCO <T>(IDbCommand cmd, ParseToPOCO <T> parsePOCO_method, IDbDataParameter[] paras = null) { IList <T> list = null; this.Set_Parameters(cmd, paras); using (IDataReader reader = cmd.ExecuteReader()) { list = RowsMapping <T>(reader, parsePOCO_method); } return(list); }