public static IList <T> GetQueryOver <T>(IQueryOver <T, T> query, List <SortOrder <T> > expressionOrder, Pagination pagination) { if (expressionOrder != null) { for (int i = 0; i < expressionOrder.Count; i++) { var model = expressionOrder[i]; IQueryOverOrderBuilder <T, T> sort; if (i > 0) { sort = query.ThenBy(model.value); } else { sort = query.OrderBy(model.value); } if (model.searchType == EnumBase.OrderType.Asc) { query = sort.Asc; } else { query = sort.Desc; } } } if (pagination != null) { query.Skip((pagination.pageIndex - 1) * pagination.pageSize); query.Take(pagination.pageSize); } var list = query.List <T>(); return(list); }
/// <summary> /// Order by /// </summary> /// <param name="source"><see cref="IQueryOver{TRoot}"/></param> /// <param name="orders"><see cref="IList{T}"/></param> /// <typeparam name="T"></typeparam> /// <returns><see cref="IQueryOver{TRoot}"/></returns> public static IQueryOver <T, T> OrderBy <T>(this IQueryOver <T, T> source, IList <Expression <Func <T, object> > > orders) { if (orders != null && orders.Any()) { source.OrderBy(orders[0]); for (var i = 1; i < orders.Count; i++) { source.ThenBy(orders[1]); } } return(source); }
public static IQueryOver <People, People> Ordering(this IQueryOver <People, People> model, IEnumerable <OrderClause> orderClauses) { if (orderClauses != null) { var first = orderClauses.First(); var x = Expression.Parameter(typeof(People), "x"); var body = Expression.PropertyOrField(x, first.Field); var conversion = Expression.Convert(body, typeof(object)); var lambda = Expression.Lambda <Func <People, object> >(conversion, x); model = first.OrderDirection.ToLower().Equals("ascending", StringComparison.InvariantCultureIgnoreCase) ? model.OrderBy(lambda).Asc : model.OrderBy(lambda).Desc; if (orderClauses.Count() > 1) { foreach (var thenByOrder in orderClauses.Skip(1)) { var y = Expression.Parameter(typeof(People), "y"); var thenByBody = Expression.PropertyOrField(y, thenByOrder.Field); var thenByConversion = Expression.Convert(thenByBody, typeof(object)); var thenByLambda = Expression.Lambda <Func <People, object> >(thenByConversion, y); model = thenByOrder.OrderDirection.ToLower().Equals("ascending", StringComparison.InvariantCultureIgnoreCase) ? model.ThenBy(thenByLambda).Asc : model.ThenBy(thenByLambda).Desc; } } } return(model); }
public IQueryBuilder <T> ThenBy(Expression <Func <T, object> > expression) { _query.ThenBy(expression).Asc(); return(this); }