/// <summary> /// 查询,返回条件页的实体列表 /// 查询的SQL语句有两个,第一个返回总的数量,第二个返回数据结果集 /// 查询条件可以使用参数,也可以自己定义拼装,注意拼装时,对参数值都使用SetSafeParameter(string parameterValue)处理一下。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="filter"></param> /// <returns></returns> public QueryResult <T> Query <T>(QueryFilter filter, string defaultSortBy, Action <DataRow, T> manualMapper = null) where T : class, new() { DataSet ds = _queryExecute(filter, defaultSortBy); int count = int.Parse(ds.Tables[0].Rows[0][0].ToString()); QueryResult <T> result = new QueryResult <T>(); result.PageIndex = filter.PageIndex; result.PageSize = filter.PageSize; result.SortFields = filter.SortFields; result.draw = filter.draw; result.recordsTotal = count; if (ds.Tables[1] != null && ds.Tables[1].Rows != null && ds.Tables[1].Rows.Count > 0) { result.data = DataMapperHelper.GetEntityList <T, List <T> >(ds.Tables[1].Rows, true, true, manualMapper); } else { result.data = new List <T>(); } if (ds.Tables.Count >= 3) { result.Summary = ds.Tables[2].Rows[0][0] != null ? ds.Tables[2].Rows[0][0].ToString().Trim() : ""; } return(result); }
public List <SODiscountMaster> GetSODiscountBySOSysNo(int sosysno) { IDataCommand cmd = IocManager.Instance.Resolve <IDataCommand>(); cmd.CreateCommand("GetSODiscountBySOSysNo"); //DataCommand cmd = new DataCommand("GetSODiscountBySOSysNo"); cmd.SetParameter("@SOSysNo", DbType.Int32, sosysno); DataSet ds = cmd.ExecuteDataSet(); List <SODiscountMaster> dmList = null; if (ds != null && ds.Tables.Count > 1) { dmList = DataMapperHelper.GetEntityList <SODiscountMaster, List <SODiscountMaster> >(ds.Tables[0].Rows); if (dmList != null && dmList.Count > 0) { List <SODiscountDetail> ddList = DataMapperHelper.GetEntityList <SODiscountDetail, List <SODiscountDetail> >(ds.Tables[1].Rows); foreach (var dm in dmList) { dm.Details = ddList.FindAll(dd => dd.MasterSysNo == dm.SysNo); } } } return(dmList); }
/// <summary> /// 执行返回对象列表 /// </summary> /// <typeparam name="T">实体类型,必须是可无参实例化的class</typeparam> /// <param name="manualMapper">可以手动mapping</param> /// <returns></returns> public List <T> ExecuteEntityList <T>(Action <DataRow, T> manualMapper = null) where T : class, new() { DataTable dt = ExecuteDataTable(); List <T> list = new List <T>(); if (dt != null && dt.Rows.Count > 0) { list = DataMapperHelper.GetEntityList <T, List <T> >(dt.Rows, true, true, manualMapper); } return(list); }