/// <summary> /// 查询排序 /// </summary> /// <param name="queryConditions"></param> /// <param name="orderList"></param> /// <returns></returns> public IList <T> GetPaged(IList <ICriterion> queryConditions, IList <Order> orderList, int pageIndex, int pageSize, out int count) { //1.符合条件的总记录数 count = ActiveRecordBase.Count(typeof(T), queryConditions.ToArray()); //2.符合条件的分页获取对象集 return(ActiveRecordBase.SlicedFindAll(typeof(T), pageIndex * pageSize, pageSize, orderList.ToArray(), queryConditions.ToArray()) as IList <T>); }
/// <summary> /// 查询获取数据记录数 /// </summary> /// <param name="queryConditions">查询条件</param> /// <returns></returns> public int GetRecordCountByFields(IList <ICriterion> queryConditions) { //1.符合条件的总记录数 int count = ActiveRecordBase.Count(typeof(T), queryConditions.ToArray()); //2.符合条件的分页获取对象集 return(count); }
/// <summary> /// 按HQL查询数量 /// </summary> /// <param name="_whereHql"></param> /// <param name="_whereParams"></param> /// <returns></returns> public static Int32 FindCountByHql(string _whereHql, object[] _whereParams) { Type tt = typeof(T); string filter = "1=1 " + _whereHql; int count = ActiveRecordBase.Count(tt, filter, _whereParams);//获得总条数 return(count); }
private static void doPage(int pagesize, ref int pageindex, out int rowscount, out int pagecount, params NHibernate.Expression.ICriterion[] criteria) { rowscount = ActiveRecordBase <T> .Count(criteria); if (pageindex < 1) { pageindex = 1; } pagecount = 0; pagecount = rowscount / pagesize; if ((rowscount % pagesize) > 0) { pagecount += 1; } if (pageindex > pagecount) { pageindex = pagecount; } }
/// <summary> /// 分页查询 /// </summary> /// <param name="whereHql">以and开始,例如"and name=?"</param> /// <param name="whereParams">对应whereHql的参数(?)</param> /// <param name="orderSql">排序sql,例如"name desc, id desc"</param> /// <param name="pageSize">每页显示条数</param> /// <param name="pageNo">要查询的页数</param> /// <returns></returns> public static SPagintion <T> FindByPagintion(string _whereHql, object[] _whereParams, string _orderSql, int _pageSize, int _pageNo) { try { if (_pageNo < 1) { _pageNo = 1; } Type tt = typeof(T); SPagintion <T> page = new SPagintion <T>(); page.WhereSql = _whereHql; page.WhereParams = _whereParams; page.OrderSql = _orderSql; page.PageSize = _pageSize; page.CurrentPageNum = _pageNo; string filter = "1=1 " + page.WhereSql; page.TotalRecordCount = ActiveRecordBase.Count(tt, filter, page.WhereParams);//获得总条数 if (page.TotalRecordCount > 0) { string hql = "FROM " + tt.Name + " WHERE " + filter; if (page.OrderSql != null && page.OrderSql.Trim().Length > 0) { hql += " ORDER BY " + page.OrderSql; } SimpleQuery <T> sq = new SimpleQuery <T>(hql, page.WhereParams); int startRecordNum = (page.CurrentPageNum - 1) * page.PageSize; sq.SetQueryRange(startRecordNum, page.PageSize);// Mysql是分页语句 page.Data = (IList <T>)ActiveRecordBase.ExecuteQuery(sq); } return(page); } catch (Exception err) { throw err; } }
public int Count() { int re = 0; ISession ss = holder.CreateSession(typeof(Test)); ITransaction tran = ss.BeginTransaction(); try { Test t = new Test(); t.Userid = 13; t.Username = "******"; t.Loginid = "fff"; t.CreateAndFlush(); tran.Commit(); //SessionScope.Current.Flush(); } catch (Castle.ActiveRecord.Framework.ActiveRecordException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } catch (DbException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } finally { tran.Dispose(); holder.ReleaseSession(ss); } re = ActiveRecordBase.Count(typeof(Test)); return(re); }
/// <summary> /// 分页获取满足条件的实体 /// </summary> /// <param name="queryConditions">查询条件</param> /// <param name="orderList">排序属性列表</param> /// <param name="pageIndex">页码</param> /// <param name="pageSize">每页实体数</param> /// <param name="count">总实体数</param> /// <returns></returns> public IList <T> Qry(IList <ICriterion> queryConditions, IList <Order> orderList, int pageIndex, int pageSize, out int count) { if (queryConditions == null) { queryConditions = new List <ICriterion>(); } //根据查询条件获取满足条件的对象总数 count = ActiveRecordBase.Count( typeof(T) , queryConditions.ToArray()); if (orderList == null) { orderList = new List <Order>(); } //根据查询条件分页获取对象集合 return(ActiveRecordBase.SlicedFindAll( typeof(T) , (pageIndex - 1) * pageSize , pageSize , orderList.ToArray() , queryConditions.ToArray() ) as IList <T>); }
/// <summary> /// Queries the DB for the count of all existing Accounts. /// </summary> /// <returns></returns> internal static int GetCount() { return(ActiveRecordBase <Account> .Count()); }
/// <summary> /// 获得条数 /// </summary> /// <param name="criteria"></param> /// <returns></returns> public static int Count(params NHibernate.Expression.ICriterion[] criteria) { return(ActiveRecordBase <T> .Count(criteria)); }
public static int GetCount() { return(ActiveRecordBase <CharacterRecord> .Count()); }
public new static int Count() { return(ActiveRecordBase <Operator> .Count()); }