public IEnumerable <T> QueryItems <T>(Expression <Func <T, bool> > predicate, Tuple <bool, Expression <Func <T, object> > > isOrderByASC = null, Tuple <bool, Expression <Func <T, object> > > isThenByASC = null) where T : class, new() { try { SQLinq <T> query = new SQLinq <T>().Where(predicate); if (isOrderByASC != null) { if (isOrderByASC.Item1) { query.OrderBy(isOrderByASC.Item2); } else { query.OrderByDescending(isOrderByASC.Item2); } } if (isThenByASC != null) { if (isThenByASC != null) { query.ThenBy(isThenByASC.Item2); } else { query.ThenByDescending(isThenByASC.Item2); } } using (IDbConnection dbConnection = new SqlConnection(this.ConnectionString)) { dbConnection.Open(); return(dbConnection.Query <T>(query)); } } catch (Exception ex) { throw ex; } }
//getPagedEntities not use public IEnumerable <T> GetPagedEntities(int pageSize, int pageIndex, out int total, Expression <Func <T, bool> > predicate, Expression <Func <T, object> > keySelector, bool isAsc) { int skipCount = pageSize * (pageIndex - 1); total = 0; //create sqlQuery SQLinq <T> query = new SQLinq <T>().Where(predicate); if (isAsc) { query = query.OrderBy(keySelector); } else { query = query.OrderByDescending(keySelector); } query.Skip(skipCount).Take(pageSize); //do query return(Query(query)); }