protected void SetOrder(ICriteria criteria, SortParam param) { if (string.IsNullOrWhiteSpace(param.Field)) { return; } criteria .AddOrder(param.Direction == ListSortDirection.Ascending ? Order.Asc(param.Field) : Order.Desc(param.Field)); }
public virtual ICriteria Apply <TEntity, TKey>(ICriteria criteria, IResultTransformer transformer, bool requiredTransform) where TEntity : Entity <TKey> { if (this.SortParams == null || this.SortParams.Length == 0) { this.SortParams = new[] { SortParam.Create <TEntity>(x => x.Id, ListSortDirection.Ascending) } } ; if (this.Count > 0) { criteria.SetFirstResult(this.Offset).SetMaxResults(this.Count); } var projectionList = Projections.ProjectionList(); foreach (var field in this.Fields) { projectionList.Add(Projections.Property(field), field); } this.AddComputedProjections(projectionList); if (projectionList.Length != 0) { criteria.SetProjection(projectionList); } this.SetTransformer(criteria, requiredTransform, projectionList, transformer); foreach (var item in this.SortParams) { SetOrder(criteria, item); } return(this.ApplyCustomFilter(criteria)); }