/// <summary> /// 按HQL查询 /// </summary> /// <param name="_whereHql"></param> /// <param name="_whereParams"></param> /// <param name="_orderSql"></param> /// <returns></returns> public static IList <T> FindByHql(string _whereHql, object[] _whereParams, string _orderSql) { Type tt = typeof(T); string hql = "From " + tt.Name + " Where 1=1 " + _whereHql; if (_orderSql != null && _orderSql.Trim().Length > 0) { hql += " Order By " + _orderSql; } SimpleQuery <T> sq = new SimpleQuery <T>(hql, _whereParams); IList <T> result = (IList <T>)ActiveRecordBase.ExecuteQuery(sq); return(result); }
/// <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; } }
/// <summary> /// Executes the query /// </summary> /// <param name="q">The query</param> /// <returns></returns> public static object ExecuteQuery(IActiveRecordQuery q) { return(ActiveRecordBase.ExecuteQuery(q)); }
public override IList Execute() { return((IList)ActiveRecordBase.ExecuteQuery(this)); }