/// <summary> /// /// </summary> /// <typeparam name="TSource"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <param name="exp"></param> /// <param name="optor"></param> /// <param name="dao"></param> /// <param name="conn"></param> /// <param name="trns"></param> /// <returns></returns> private static T QueryAggregate <TSource, T>( TSource model, Expression <Func <TSource, T> > exp, string optor, IDBUtil dao, DbConnection conn = null, DbTransaction trns = null) where TSource : IDBEntity { //要查詢的欄位 string propName = ((MemberExpression)exp.Body).Member.Name; //處理 where 參數 var whereParams = prepareWhereParams(model.GetOperating().WHERE_LIST); var selectColumns = new List <string>(); selectColumns.Add(optor + "(" + propName + ") AS result"); //查詢 var resultList = dao.QueryByTable(model.GetTableName(), selectColumns, whereParams, conn, trns); if (resultList != null && resultList.Count > 0 && !DBNull.Value.Equals(resultList[0]["result"])) { Func <object, object> converter = ClassUtil.GetConvertFuncMap()[typeof(T)]; return((T)converter(resultList[0].SafeGetValue("result"))); } return(default(T)); }