protected List <TModel> GetPagedRecords(SqlBuilder builder, PagingSpec <TModel> pagingSpec, Func <SqlBuilder, IEnumerable <TModel> > queryFunc) { AddFilters(builder, pagingSpec); var sortDirection = pagingSpec.SortDirection == SortDirection.Descending ? "DESC" : "ASC"; var pagingOffset = (pagingSpec.Page - 1) * pagingSpec.PageSize; builder.OrderBy($"{pagingSpec.SortKey} {sortDirection} LIMIT {pagingSpec.PageSize} OFFSET {pagingOffset}"); return(queryFunc(builder).ToList()); }
protected List <TModel> GetPagedRecords(SqlBuilder builder, PagingSpec <TModel> pagingSpec, Func <SqlBuilder, IEnumerable <TModel> > queryFunc) { AddFilters(builder, pagingSpec); if (pagingSpec.SortKey == null) { pagingSpec.SortKey = $"{_table}.{_keyProperty.Name}"; } var sortKey = TableMapping.Mapper.GetSortKey(pagingSpec.SortKey); var sortDirection = pagingSpec.SortDirection == SortDirection.Descending ? "DESC" : "ASC"; var pagingOffset = Math.Max(pagingSpec.Page - 1, 0) * pagingSpec.PageSize; builder.OrderBy($"\"{sortKey}\" {sortDirection} LIMIT {pagingSpec.PageSize} OFFSET {pagingOffset}"); return(queryFunc(builder).ToList()); }