Exemple #1
0
 public IList <T> GetAll <T>(int pageIndex, int pageSize, out int totalCount, params SortInfo[] orderBy) where T : new()
 {
     PreconditionAssert.IsNotNull(orderBy, ErrorMessages.NullReferenceException);
     ORMHelper.EntityIsMappingDatabase(typeof(T), ErrorMessages.EntityMappingError);
     try
     {
         SelectCommandCreator dbCommandCreator = new SelectCommandCreator(dbAccess);
         dbCommandCreator.ObjectType = typeof(T);
         dbCommandCreator.OrderBy    = orderBy;
         dbCommandCreator.SelectType = SelectType.GetAll;
         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)
     {
         throw new ORMException("Get all object list error, detail:\n\t" + ORMHelper.GetOrderInfoMessage(orderBy), ex);
     }
 }
Exemple #2
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);
     }
 }
Exemple #3
0
        public IList <T> GetAll <T>(params SortInfo[] orderBy) where T : new()
        {
            PreconditionAssert.IsNotNull(orderBy, ErrorMessages.NullReferenceException);
            ORMHelper.EntityIsMappingDatabase(typeof(T), ErrorMessages.EntityMappingError);
            try
            {
                SelectCommandCreator dbCommandCreator = new SelectCommandCreator(dbAccess);
                dbCommandCreator.ObjectType = typeof(T);
                dbCommandCreator.OrderBy    = orderBy;
                dbCommandCreator.SelectType = SelectType.GetAll;
                DbCommand dbCommand = dbCommandCreator.GetDbCommand();

                DataTable dt = dbAccess.GetDataTableByCommand(dbCommand);
                return(ORMHelper.DataTableToList <T>(dt));
            }
            catch (Exception ex)
            {
                throw new ORMException("Get all object list error, detail:\n\t" + ORMHelper.GetOrderInfoMessage(orderBy), ex);
            }
        }
Exemple #4
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);
     }
 }