コード例 #1
0
 public IList <T> GetList <T>(Criteria criteria, params SortInfo[] orderBy)
     where T : new()
 {
     PreconditionAssert.IsNotNull(criteria, ErrorMessages.NullReferenceException);
     try
     {
         SelectCommandCreator dbCommandCreator = new SelectCommandCreator(dbAccess);
         dbCommandCreator.OrderBy    = orderBy;
         dbCommandCreator.ObjectType = typeof(T);
         dbCommandCreator.Cri        = criteria;
         dbCommandCreator.SelectType = SelectType.GetList;
         DbCommand dbCommand = dbCommandCreator.GetDbCommand();
         DataTable dt        = dbAccess.GetDataTableByCommand(dbCommand);
         return(ORMHelper.DataTableToList <T>(dt));
     }
     catch (Exception ex)
     {
         StringBuilder errMsgBuilder = new StringBuilder();
         errMsgBuilder.AppendLine("Select object list by criteria error, detail:");
         errMsgBuilder.AppendLine("Criteria Info:");
         errMsgBuilder.AppendLine(ORMHelper.GetCriteriaMessage(criteria));
         errMsgBuilder.AppendLine("Sort Info:");
         errMsgBuilder.AppendLine(ORMHelper.GetOrderInfoMessage(orderBy));
         throw new ORMException(errMsgBuilder.ToString(), ex);
     }
 }
コード例 #2
0
 public IList <T> GetList <T>(Criteria criteria, int pageIndex, int pageSize, out int totalCount, params SortInfo[] orderBy)
     where T : new()
 {
     PreconditionAssert.IsNotNull(criteria, ErrorMessages.NullReferenceException);
     try
     {
         SelectCommandCreator dbCommandCreator = new SelectCommandCreator(dbAccess);
         dbCommandCreator.OrderBy    = orderBy;
         dbCommandCreator.ObjectType = typeof(T);
         dbCommandCreator.Cri        = criteria;
         dbCommandCreator.SelectType = SelectType.GetList;
         dbCommandCreator.NeedPaged  = true;
         dbCommandCreator.PageIndex  = pageIndex + 1;
         dbCommandCreator.PageSize   = pageSize;
         DbCommand dbCommand = dbCommandCreator.GetDbCommand();
         DataTable dt        = dbAccess.GetDataTableByCommand(dbCommand);
         if (dt.Rows.Count > 0)
         {
             totalCount = (int)dt.Rows[0]["TotalCount"];
         }
         else
         {
             totalCount = 0;
         }
         return(ORMHelper.DataTableToList <T>(dt));
     }
     catch (Exception ex)
     {
         StringBuilder errMsgBuilder = new StringBuilder();
         errMsgBuilder.AppendLine("Select object list by criteria error with page, detail:");
         errMsgBuilder.AppendLine("Criteria Info:");
         errMsgBuilder.AppendLine(ORMHelper.GetCriteriaMessage(criteria));
         errMsgBuilder.AppendLine("Page Info:");
         errMsgBuilder.AppendLine("PageIndex:" + pageIndex + "; PageSize:" + pageSize);
         errMsgBuilder.AppendLine("Sort Info:");
         errMsgBuilder.AppendLine(ORMHelper.GetOrderInfoMessage(orderBy));
         throw new ORMException(errMsgBuilder.ToString(), ex);
     }
 }